Can anyone tell me the difference between Javascript Object and JSON object with an example?
Can anyone tell me the difference between Javascript Object and JSON object with an
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A Javascript object is a data type in Javascript – it makes sense only in Javascript. Often you see a Javascript object literal like this:
A JSON string is a data interchange format – it is nothing more than a bunch of characters formatted a particular way (in order for different programs to communicate with each other). Because of this, it can exist inside Javascript, or in another language or simply stored inside a database or a text file.
The above Javascript object can be represented in the JSON format in Javascript like this:
Or in C# like this:
As you can see, a JSON is simply stored inside a string. To make it useful, the JSON string can be parsed to produce an object in any language. Because the JSON format mimics Javascript’s object literal syntax, Javascript makes the parsing process easy:
Though typically you’d see:
Note that JSON is limited in that it cannot store functions – the only values it can contain are: