Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting JSON Structure to BasicDBObject

Tags:

java

mongodb

I want to convert the following json structure to BasicDBOject in java and insert into mongo db.

My JSON structure is

{
    "it": {
        "batch": "2013",
        "students": [
            {
                "name": "joe"
            },
            {
                "name": "john"
            }
        ]
    }
}
like image 464
user2189941 Avatar asked May 02 '13 08:05

user2189941


1 Answers

com.mongodb.util.JSON has a parse method.

BasicDBObject implements DBObject

Object o = com.mongodb.util.JSON.parse("Your JSON structure or JSONObj.toString()");
DBObject dbObj = (DBObject) o;
like image 96
Alper Avatar answered Oct 06 '22 09:10

Alper