JSON-to-XML - dead simple

2008-02-01 @ 22:59#

i finally got a JSON-to-XML converter working this evening. it was a bit dicey at first, but i got it working the way i like.

first, i've seen several of these XML/JSON tools. but none of them worked the way i liked. first, most of the tools focused on turning XML into JSON - not my problem. I plan on doing that using XSLT. besides, most of the ones i've seen decorate the JSON with "@" or "#" added to the names, etc. all icky. finally, i really only need this JSON-to-XML tool so i can make sure i have a valid XML document to work with inside the exyus engine. i just need the JSON i accept on PUT/POST to be consistently converted to XML so i can use XSD/XSLT on it to get my work done.

so anyway, i got it working the way i like. here's the JSON and resulting XML from a simple example:

{task:{'id' : 'x8ca2f68ed5464b2', 'seq' : '1', 'name' : 'Read TaskList Tutorial', 'is-completed' : '1'}}

<root>
  <task>
    <is-completed>1</is-completed> 
    <name>Read Mike's TaskList Tutorial</name> 
    <seq>1</seq> 
    <id>x8ca2f68ed5464b2</id> 
  </task>
</root>

pretty simple. nice. i've got a couple other things to test (more complex objects, naming issues, etc.) but i should have those done later this evening. when it's done, i'll post a more complete example along with the source.

code