0

I'm learning javascript and just noticed that the syntax we use to define objects is the same as the json format. So I'm wondering if they are simply equivalent. Being more precise, does it mean that any javascript object (including its variables and functions) can be translated into json format and the same way around?

4

3 Answers 3

2

JSON is (like it's name "JavaScript Object Notation" indicates) a subset* of the JavaScript syntax, i.e. (nearly) every* JSON is valid JavaScript but not the other way round.

Functions, for example, have no equivalent representation in JSON and therefore, cannot be translated into JSON. Since the main purpose for JSON is serialization, it doesn't provide representation of statements either.

* There is one exception: more or less all Unicode characters can be written literally in JSON but they must be written using escape sequences in JavaScript. See this blog post for more information. So not every valid JSON is valid JavaScript.

Sign up to request clarification or add additional context in comments.

Comments

0

JSON data has only data specified in key-value pairs; where as js objects contain both data and functions enlisted in key-value pairs.

Comments

0

Think of JSON as a string representation of your javascript object. - String being the key word here.

Primarily used for easy transport over HTTP .It is a method created by Douglas Crockford to enable a friendly Javascript data transfer format similar to XML , RSS, et all.

JSON is generally parsed by server and client back into a Javascript object for use.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.