how do you get objects for events -> performances -> name & occurs_at to this json file https://api.myjson.com/bins/w05x using javascript. Cannot use regex since json API keeps changing format. Thanks
Asked
Active
Viewed 23 times
0
-
2See [Safely turning a JSON string into an object](http://stackoverflow.com/questions/45015/safely-turning-a-json-string-into-an-object) and [Access / process (nested) objects, arrays or JSON](http://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json) – Jonathan Lonowski Nov 14 '15 at 01:23
-
Can you please show what you've tried? For just accessing data given as JSON, you shouldn't have any need for using Regex. While the data in the document may change, the structure / arrangement of the data should remain fairly similar (the root value is an object, its `events` is an array of more objects, etc.), barring the developers behind the API being terribly inconsistent. If you're not sure how to start, the 2nd Q&A I linked to offers a good explanation on how to traverse the objects and arrays holding the data you'd like to access. – Jonathan Lonowski Nov 14 '15 at 01:40
-
I tried this regex (?<=occurs_at\"\:\").*?(?=\")|(?<=\"performer\"\:\{\"slug\"\:\").*?(?=\"\,\")|(?<=location\"\:\").*?(?=\,\") and amaybe a week or two it changes so I have to update regex everytime it happens – markos markos Nov 14 '15 at 01:45
1 Answers
0
Use the JSON parser
obj = JSON.parse(json_string);
then you access it with
obj.events[event_index].performances[performance_index].performer.name
obj.events[event_index].name
obj.events[event_index].occurs_at
JSFiddle example of listing all the event attributes name
and occurs_at
.

gre_gor
- 6,669
- 9
- 47
- 52
-
Sorry to bother. Can you show it on jsfiddle or codepen. Thanks. appreciate your answer – markos markos Nov 14 '15 at 01:30
-
-