How to access data from API response

So, I was working on gather data from a “streams” request, and as I was working through gathering the data, I ran into a road block. The data is structured like this

{“data”:[{“id”:“user-id”,“login”:“u-login”,“display_name”:“ds-name”,“type”:"",“broadcaster_type”:“partner”,“description”:“User-Descripton “,“profile_image_url”:“profile-url”,“offline_image_url”:“offline-url”,“view_count”:502504},{“id”:“user-id”,“login”:“u-login”,“display_name”:“ds-name”,“type”:””,“broadcaster_type”:“partner”,“description”:“Eat. Sleep. Stream. Repeat. #KeepWinning”,“profile_image_url”:“url-profile”,“offline_image_url”:“off-url”,“view_count”:106110}]}

Normally, I would parse this data in an object, then do, but in this data, the second layer of json is inside a pair of [ ], how do you access, for example, the display_name?

In Javascript

var data = JSON.parse(the_result);
var display_name =[0].display_name;

That is to say, it’s an object, with a element of key data, where that element is an array of objects (and in this case there is only a single object in that array)

Ok, that works. Thanks a lot! :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.