jQuery.parseJSON('{"name":"John"}')
converts string representation to object
but I want the reverse. Object is to be converted to JSON string
I got a link http://www.devcurry.com/2010/03/convert-javascript-object-to-json.html
but it need to have json2.js do jQuery has a native method to do this?
Also useful is Object.toSource() for debugging purposes, where you want to show the object and its properties for debugging purposes. This is a generic Javascript (not jQuery) function, however it only works in "modern" browsers.
You can use the excellent jquery-Json plugin:
http://code.google.com/p/jquery-json/
Makes it easy to convert to and from Json objects.
Convert JavaScript object to json data
$("form").submit(function(event){
event.preventDefault();
var formData = $("form").serializeArray(); // Create array of object
var jsonConvertedData = JSON.stringify(formData); // Convert to json
consol.log(jsonConvertedData);
});
You can validate json data using http://jsonlint.com
Source: Stackoverflow.com