Parsing JSON from URL?

Hello, I’m trying to find a way to fetch a JSON from this URL in Supercollider:
https://data.buienradar.nl/2.0/feed/json

My idea is to either fetch the content of the web page as a string, and then formatting it as a JSON, or getting a JSON file straight away, to ultimately automate this process and loop it every X minutes to update the data displayed. Does anybody knows a way? I haven’t found anything to perform this kind of operation easily, maybe WebView somehow?

Thanks for the help :slight_smile:

Assuming you are on something unix-like

~data_json = "curl https://data.buienradar.nl/2.0/feed/json".unixCmdGetStdOut(999999999).parseJSON
1 Like

That’s great, thanks! I have a follow-up question: if I wanna have a clear vision over the content of the JSON object, and for instance access a certain subdictionary within a dictionary, how could I do it?

~data_json.keys // Set[ actual, forecast, buienradar, $id ]
~data_json["actual"].keys // Set[ sunrise, actualradarurl, $id, sunset, stationmeasurements ]
~data_json["actual"]["sunrise"] // 2023-01-21T08:35:00

or to explore the keys…

~list_all_keys = { |json, currentKey="top", lvl=1|
	try {
		var keys = json.keys;
		if(keys.size > 0, {
			postf("% %: %\n", ($\t ! (lvl - 1)).reduce('++') ? "", currentKey ? "", keys)
		});
		keys.do{|k| ~list_all_keys.(json[k], k, lvl + 1) }
	}{}
};

~list_all_keys.(~data_json, "data_json")

which returns…

 data_json: Set[ actual, forecast, buienradar, $id ]
	 actual: Set[ sunrise, actualradarurl, $id, sunset, stationmeasurements ]
	 forecast: Set[ weatherreport, fivedayforecast, shortterm, $id, longterm ]
		 weatherreport: Set[ text, summary, published, title, $id, author, authorbio ]
		 shortterm: Set[ startdate, forecast, enddate, $id ]
		 longterm: Set[ startdate, forecast, enddate, $id ]
	 buienradar: Set[ copyright, terms, $id ]
1 Like

WOW amazing!!! thank you so much!!