Home > DeveloperSection > Forums > How to parse into JSON object using JSON.parse() in Node.js
Pravesh Singh
Pravesh Singh

Total Post:101

Points:709
Posted on    April-02-2013 2:40 AM

 JavaScript JavaScript 
Ratings:


 1 Reply(s)
 5582  View(s)
Rate this:
Hi Guys

I am having the following string object and I want to create a JSON object out of it and store it in MongoDB.

    var strMYDATA = '{"Name":"ABC","SignedDate" : ISODate("2013-04-02T09:07:42.282Z")}';
I tried the following to create a JSON object out of strMYDATA

    var JSONobj = JSON.parse(strMYDATA);
    console.dir(JSONobj);
Getting the following error:

undefined:1
 "Name":"ABC","SignedDate" : ISODate("2
                              ^
SyntaxError: Unexpected token I
    at Object.parse (native)
Could anyone know how to parse the string with ISO date field like above in Node.JS?

Note: Cannot change the strMYDATA content because it a serialized object received from other Node.JS restful API.

Thanks



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    April-02-2013 7:31 AM

Hi Pravesh!

Your JSON data is bad. You have unescaped strings in your data.

var strMYDATA = '{"Name":"ABC","SignedDate" : "ISODate("2013-04-02T09:07:42.282Z")"}';

should be

var strMYDATA = '{"Name":"ABC","SignedDate" : "ISODate(\"2013-04-02T09:07:42.282Z\")"}';

Don't want to miss updates? Please click the below button!

Follow MindStick