Easily Transform JSON with json2json

I have been working on an auto-complete web service that searches Amazon’s Product Advertising API.  I built it in Node.js and using the APAC package made it really easy to query the API. The only thing that was extremely impractical was the JSON data returned by APAC.

Since Amazon’s API only returns data as XML, APAC uses xml2json to convert the XML to JSON. Unfortunately the resulting JSON is quite ugly. I wanted to be able to choose the data I needed and copy it to a new, clean JSON format. My solution was to create json2json.

json2json lets you create a template that describes how to transform the original JSON to a new structure. I wrote the Node.js package and example template in CoffeeScript because it has a much cleaner and simpler syntax than JavaScript. However, it is extremely simple to convert to JavaScript (click on “Try CoffeeScript”) and can easily be modified for use in a browser. Check out the (crude) documentation and example files and let me know what you think.

Share

5 comments

  1. Hi, this looks great and I’d really like to use this in a browser instead of a Node environment. Is there any chance you could provide a version that runs in a browser, or provide guidance on how to modify it? I would we willing to be your tester. :)

  2. Hi Aaron,

    I updated the json2json code on GitHub to handle running in the browser. There’s a little blurb at the bottom of the README that shows what files you should include. Let me know if it works. :-)

    ~Joel

  3. Joel,

    Is JSON 2 JSON under active development? This looks like something that I could use. I started following CoffeeScript recently. It looks like that language is under active development. I have been playing around with JSON 2 JSON, both as something useful in itself, and also as an application and example of the use of CoffeeScript.

  4. Hi Cliff,

    I haven’t worked on json2json in a while, but may revamp it in a new version. Try it out and let me know what you think.

  5. This library looks very promising. Keep up the good work.

Leave a Reply

Your email address will not be published. Required fields are marked *


6 + nine =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Additional comments powered by BackType