Converting to XML or reading JSON API Responses

  • 13 September 2017
  • 3 replies
  • 22 views

Badge +4

There is an action called "Query XML". Is there a way to use this in some form to query a JSON response? I'm trying to integrate the Google API to return the timezone of a set of lat / lon coordinates and I cannot parse the response of the JSON. I'm also not sure how effective it would be to use the various string manipulators to read through and parse out a specific line of varying data sets. Can anyone assist with this or is this even possible?


3 replies

Badge +4

well hopefully someone will see this, but amazingly enough this was even easier than I thought, I discovered this by pure accident.

Within the query to google api there's a /json, 

https://maps.googleapis.com/maps/api/timezone/json?location=CoordsHere&timestamp=1458000000&key=APIKeyHere

... and I thought "I wonder if you can just put /xml in there and make it work?" So I go and flip the "json" to "xml" and amazingly, it returns it in XML instead of JSON.

https://maps.googleapis.com/maps/api/timezone/xml?location=CoordsHere&timestamp=1458000000&key=APIKeyHere

I scoured the internet for hours and so many other people were asking this but no one could answer that question. The "correct answer" was always "parse it into XML yourself" or "Write your own converter" blah blah... and it was in there the whole time.

Userlevel 5
Badge +14

FYI, it's documented here - Developer's Guide  |  Google Maps Geocoding API  |  Google Developers 

Badge +4

I knew it had to be somewhere in there. It was far to easy for me to figure it out for them to leave it out of their docs. I did searches for "Google API XML output", I did many other searches, I even did a feature search through their knowledge base for "output as XML" and it came up with no results. I ended up putting in a feature request for it to output as XML since I couldn't find it in their docs. (They're really fast at implementing new features! silly.png)

Thanks for the link! I hadn't bothered to check the "basic" guide, only the ones specific to the API service I was using.

Reply