tags:

views:

89

answers:

4

How can I take a JSON object and convert it back into the original string format?

Thanks

+4  A: 

You could use an excelent json2.js library: http://json.org/json2.js

Check out the JSON.stringify method.

rochal
I did not see your post at first, I vote this up.
Anders
A: 

There are a few jQuery plugins to do this. jQuery-json is one of them, which I've tried successfully.

Bruno
A: 

Use the stringify method from Douglas Crockford's JSON object:

http://www.json.org/js.html

This will show your object in an alert box:

alert(JSON.stringify(myObject));
Silkster
no jquery support?
James moore
Why would you need jquery support? After all it's pure javascript.
Xavier Combelle
the JSON library is not part of jQuery, but it is very useful. I highly recommend using it.
Silkster
+1  A: 

when it's an object, it's a javascript object, then it gets encoded as a string, a string that is a javascript syntax that expresses the object json-encoded. (JSON: JavaScript Object Notation).

However, these are the jquery built in function to parse json is jQuery.getJSON (retrieves the object out of the string).

to do things the other way around check this: http://stackoverflow.com/questions/191881/serializing-to-json-in-jquery

aularon