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

Total Post:101

Posted on    April-02-2013 2:40 AM

 JavaScript JavaScript 

 1 Reply(s)
 6147  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);
Getting the following error:

 "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.



Total Post:604

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