Probelm to fetch data

Hello I have problems getting data from an api.

Api:
{
“coord”: {
“lon”:
“lat”:
},
“weather”: [
{
“id”: 800,
“main”: “Clear”,
“description”: “clear sky”,
“icon”: “01d”
}
],
“base”: “stations”,
“main”: {
“temp”: 304.17,
“feels_like”: 305.8,
“temp_min”: 304.17,
“temp_max”: 304.17,
“pressure”: 1012,
“humidity”: 50,
“sea_level”: 1012,
“grnd_level”: 996
},
“visibility”: 10000,
“wind”: {
“speed”: 6.49,
“deg”: 15,
“gust”: 9.5
},
“clouds”: {
“all”: 1
},
“dt”: 1617972995,
“sys”: {
“country”: “PY”,
“sunrise”: 1617963034,
“sunset”: 1618005136
},
“timezone”: -14400,
“id”: 3867291,
“name”:
“cod”: 200
}

I do not get any data from this point of the api:

weather": [
{
“id”: 800,
“main”: “Clear”,
“description”: “clear sky”,
“icon”: “01d”
}
],

is it because of these brackets? [ ]

What you pasted in has some normal quotes and some reversed quotes. Did the API return that way, or did it get mangled by copy/paste/forum/something?

indicates an array of values. You can typically use a list block to get one member of the list.

It is also in the api.
The api is from openweathermap

That’s from openweathermap.org/current? If so, you’ve somehow changed your quotes format. Here’s your API result (just the sample one from the webpage), better formatted:

    {
  "coord": {
    "lon": -122.08,
    "lat": 37.39
  },
  "weather": [
    {
      "id": 800,
      "main": "Clear",
      "description": "clear sky",
      "icon": "01d"
    }
  ],
  "base": "stations",
  "main": {
    "temp": 282.55,
    "feels_like": 281.86,
    "temp_min": 280.37,
    "temp_max": 284.26,
    "pressure": 1023,
    "humidity": 100
  },
  "visibility": 16093,
  "wind": {
    "speed": 1.5,
    "deg": 350
  },
  "clouds": {
    "all": 1
  },
  "dt": 1560350645,
  "sys": {
    "type": 1,
    "id": 5122,
    "message": 0.0139,
    "country": "US",
    "sunrise": 1560343627,
    "sunset": 1560396563
  },
  "timezone": -25200,
  "id": 420006353,
  "name": "Mountain View",
  "cod": 200
}

The square brackets means you’re getting an array of objects for “weather”, although the example only has one object in it.

You might find the last post on this thread useful - that was a similar embedded array situation: How do you get a nested json object from an array - #9 by ochapple

1 Like

Hi, please see my tutorial about APIs and JSON. It will help you to get the data you need.

2 Likes

Thanks @tatiang and @catsarisky