Serialize object to JSON

by rishi007bansod

HTML

<button id="Go">Go</button>

JavaScript

document.getElementById("Go").onclick = function()
{
    //we want to serialize this javascript object to json
    var obj = [{
    name: "UserDictionaryRecord",
    functionToApply: "",
    sel_option: "",
    dummy: "",
    toggle: false,
    showOptions:"true",
    uniqueId: 1,
    meta_row: "",
      nodes: []
    }];
    var ser = JSON.stringify(obj);
    alert(ser);

    //deserialize back into an object using javascript
    var objCopy = JSON.parse(ser);
    alert(objCopy[0].name);

    
    //while you can use both jquery and native js to parse json, it seems that only native javascript offers
    //a way to serialize a javascript object to json.
};