@Herodotus

Как достать данные из json файла, где не назван массив?

[
  {
    "id": 11,
    "image": "images/1280px-bernard_harris_and_michael_foale_prepare_to_leave_airlock_-_gpn-2006-000022.jpg",
    "tags": [
      "cosmonauts"
    ],
    "title": "Bernard Harris: The First African American to Perform a Spacewalk",
    "url": "/catalog/image/11",
	"age": 3,
	"rating": 3
  },
  {
    "id": 12,
    "image": "images/potw2009a.jpg",
    "tags": [
      "hubble",
      "galaxy",
      "galacticjam"
    ],
    "title": "Hubble Spies Galactic Traffic Jam",
    "url": "/catalog/image/12",
	"age": 5,
	"rating": 4
  },
  {
    "id": 13,
    "image": "images/EQYxPHmU0AEfdX3.jpg",
    "tags": [
      "esa",
      "nasa",
      "ship",
      "launch",
      "solarorbiter"
    ],
    "title": "Launch of the ESA/NASA Solar Orbiter",
    "url": "/catalog/image/13",
	"age": 7,
	"rating": 2
  },
  {
    "id": 14,
    "image": "images/iss061e112503.jpg",
    "tags": [
      "earth",
      "moon",
      "atmosphere"
    ],
    "title": "A waxing crescent Moon",
    "url": "/catalog/image/14",
	"age": 3,
	"rating": 5
  },
  {
    "id": 15,
    "image": "images/pia23408.jpg",
    "tags": [
      "tess",
      "planet"
    ],
    "title": "TESS Finds First Earth-Size Planet in the Habitable Zone",
    "url": "/catalog/image/15",
	"age": 12,
	"rating": 4
  },
  {
    "id": 16,
    "image": "images/1200px-Gulf_Intracoastal_Waterway_Galveston_Bay.jpg",
    "tags": [
      "earth",
      "usa"
    ],
    "title": "Houston, Texas on the Gulf Coast",
    "url": "/catalog/image/16",
	"age": 7,
	"rating": 4
  },
  {
    "id": 17,
    "image": "images/49048341728_21e121889f_o.jpg",
    "tags": [
      "sun",
      "mercury"
    ],
    "title": "Mercury's Solar Transit",
    "url": "/catalog/image/17",
	"age": 5,
	"rating": 4.5
  },
  {
    "id": 18,
    "image": "images/potw1912a.jpg",
    "tags": [
      "hubble",
      "galaxies"
    ],
    "title": "Hubble Spots Flock of Cosmic Ducks",
    "url": "/catalog/image/18",
	"age": 7,
	"rating": 4
  },
  {
    "id": 19,
    "image": "images/pia22692.jpg",
    "tags": [
      "juno",
      "jupiter"
    ],
    "title": "NASA's Juno Spacecraft Has a Close Encounter with Jupiter",
    "url": "/catalog/image/19",
	"age": 10,
	"rating": 5
  }
]


Как получить значения в js из этого файла?
Файл менять нельзя.
  • Вопрос задан
  • 88 просмотров
Решения вопроса 1
yarkov
@yarkov Куратор тега JavaScript
Помог ответ? Отметь решением.
import data from './data.json';

data[0]; // первый элемент массива из файла
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы