- Access external datastore which returns a JSON 'array' with variable number of records
- Extract from the JSON array the values of the keys I require
- Do some processing
Sample code to access and process:-
Code: Select all
put url "https://data.nsw.gov.au/data/api/3/action/datastore_search?q=2103&fields=postcode,lga_name19,notification_date,likely_source_of_infection&resource_id=2776dbb8-f807-4fb2-b1ed-184a6fc2c8aa" into myJSONVar
put JSONToArray(myJSONVar) into tJSONArray
get the keys of tJSONArray["result"]["records"]
split it by return
repeat for each element tIndex in it
put tJSONArray["result"]["records"][tIndex]["notification_date"] & tab & \
tJSONArray["result"]["records"][tIndex]["postcode"] & tab & \
tJSONArray["result"]["records"][tIndex]["likely_source_of_infection"] & tab & \
tJSONArray["result"]["records"][tIndex]["lga_name19"] & CR after myJSONData
end repeat
--comment Do some other processing
- get the keys of tJSONArray["result"]["records"]
- put tJSONArray["result"]["records"][tIndex]["notification_date"]
Or if I wanted to cycle thru the entire JSON array and when I hit the 'records' 'key', extract the 'id's (eg notification_date, postcode etc) text, and the values associated with these.