Search code examples
javascriptjsonangularstringify

JSON.stringify date convert into JSON.parse when return empty value


I have a object convert into json string using JSON.stringify() and then I need same object with using of JSON.parse(), but I get array values are empty, how to I get original data, please help to solve this issue, in below codes is stringify data

{
"agefrom":18,
"ageto":60,
"heightfrom":"1",
"heightto":"28",
"steps":["Never","One"],
"number":["One","two "],
"education":["B.E","B.E / B.Tech"]
}

below data after convert into JSON.parse

 {
        "agefrom":18,
        "ageto":60,
        "heightfrom":"1",
        "heightto":"28",
        "steps":"",
        "number":"",
        "education":""
   }

Solution

  • fiddle try this fiddle. it works fine for me.

     a = {
      "agefrom": 18,
      "ageto": 60,
      "heightfrom": "1",
      "heightto": "28",
      "steps": ["Never", "One"],
      "number": ["One", "two "],
      "education": ["B.E", "B.E / B.Tech"]
    }
    a = JSON.stringify(a)
    document.write(a);
    b = JSON.parse(a);
    document.write(JSON.stringify(b))