In Convert JSON to XML I showed how to make XML from JSON. Here’s the opposite. It could be a little more all-encompassing by dealing with dates, and unescaping, but for now, this should serve most simple needs.

There is now a webapp api of this too which you can use to convert online. See Using Apps Script for xml json conversion
How to use

Let’s start with this XML string that needs to be converted to a JSON object.

It can be used like this

The code

It’s recursive, so in the end it’s just a few lines of code. Note that it converts numbers and booleans from text in the fixValue function. This could easily be extended to convert dates or unescape strings between JSON and XML formats if necessary.

For more like this see Google Apps Scripts Snippets
Why not join our forum, follow the blog or follow me on Twitter to ensure you get updates when they are available.