Re: How to Parse a JSON Document in Mongo DB Function

196 views
Skip to first unread message

Jitendra Chopra

unread,
May 24, 2013, 1:50:29 PM5/24/13
to mongod...@googlegroups.com
Never mind.. I got solution.

var jsontext = '{"firstname":"Jesper","surname":"Aaberg","phone":["555-0100","555-0120"]}';
var jsonObject =  eval('(' + jsontext + ')');
var contact = jsonObject.firstname;

On Thursday, May 23, 2013 4:34:44 PM UTC-7, Jitendra Chopra wrote:
Hi 

I wrote a function in Mongo DB which will parse a give JSON/XML document and give me object.
I will use that function for further processing. 
When i have JSON parse it thrown below error. Can you please suggest is there any way we can parse JSON/XML Document?

"invoke failed: JS Error: ReferenceError: JSON is not defined nofile_b:11"

function (payload) {
var jsontext = '{"firstname":"Jesper","surname":"Aaberg","phone":["555-0100","555-0120"]}';
var contact = JSON.parse(jsontext);
return contact.firstname;
}

In Spring Java, i am using below code to invoke function
Object a  = mongoTemplate.getDb().eval(function);

Felipe Albrecht

unread,
Jun 8, 2013, 2:15:58 PM6/8/13
to mongod...@googlegroups.com
json documents are java script code, JSON = JavaScript Object Notation, so it is at least silly what you are doing.


2013/5/24 Jitendra Chopra <chopra....@gmail.com>

--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages