JSON   is a syntax for serializing objects, arrays, numbers, strings, booleans, and null.

It is based upon JavaScript syntax but is distinct from it: some JavaScript is not JSON, and some JSON is not JavaScript.

  1. Characteristic of JSON:
  • Property names must be double-quoted strings; trailing commas are forbidden.
  • Leading zeros are prohibited, a decimal point must be followed by at least one digit.
  • May be escape, certain control characters are prohibited.
  • The Unicode line separator and paragraph separator, characters are permitted.
  • Strings must be double-quoted.

2.  Methods:

2.1. JSON.parse:

  • Parse a string as JSON, optionally transform the produced value and its properties, and return the value.
  • Function:

A function that transforms the results. This function is called for each member of the object. If a member contains nested objects, the nested objects are transformed before the parent object. For each member, the following occurs:

If reviver returns a valid value, the member value is replaced with the transformed value.

If reviver returns the same value it received, the member value is not modified.

If reviver returns null or undefined, the member is deleted.

  • Return value: an object or array.

2.2. JSON.stringify:

  • Return a JSON string corresponding to the specified value, optionally including only certain properties or replacing property values in a user-defined manner.
  • Function:

Required. A JavaScript value, usually an object or array, to be converted.

Optional. A function or array that transforms the results.

If replacer is a function, JSON.stringify calls the function, passing in the key and value of each member. The return value is used instead of the original value. If the function returns undefined, the member is excluded. The key for the root object is an empty string: “”.

If replacer is an array, only members with key values in the array will be converted. The order in which the members are converted is the same as the order of the keys in the array. The replacer array is ignored when the value argument is also an array.

  • Return value: A string that contains the JSON text.

3. The JSON object is not supported in older browsers. You can work around this by     inserting the following code at the beginning of your scripts, allowing use of JSON object in implementations which do not natively support it (like Internet Explorer 6).

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s