JSON is a syntax for serializing objects, arrays, numbers, strings, booleans, and null.
- 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.
- Parse a string as JSON, optionally transform the produced value and its properties, and return the value.
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.
- Return a JSON string corresponding to the specified value, optionally including only certain properties or replacing property values in a user-defined manner.
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).