As we have seen in previous post’s how JSON work and what is the syntax of JSON and so on. Let’s explore JSON a little more.

I previous post we added single identity with it’s value in it. We can do alot more with it, we can add list of array it like:

>db.things.save({a : 1, b : 5, colors : ["red", "black", "blue", "yellow"]})
>db.things.find()
Output :
{ "_id" : ObjectId("5446c28646e4915b9e33dfbe"), "a" : 1, "b" : 2, "colors" : [  "red", "black", "blue", "yellow" ] }

Similarly if we want to add say ones address then it can be like :

>db.things.save({"Name" : "Deepak", "Age" : "21", "Address" : { "street" : "xyz", "House_Number" : "N-70", "City" : "abc", "Zip" : "14556" })
>db.things.find()
Output :
{ "_id" : ObjectId("5446c30c46e4915b9e33dfbf"), "Name" : "Deepak", "Age" : "21", "Address" : { "street" : "Saijida Colony", "House_Number" : "N-70", "City" : "Malerkotla", "Zip" : "148023" } }
Advertisements