Table of contents
- 1. Summary
- 1.1. JSON Notation
- 2. Description
- 3. Properties
- 4. Methods
- 5. Cross-browser compatibility
Summary
The JSON object contains methods for converting values to JSON notation and for converting JSON notation to values.
JSON Notation
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.
The main differences between standard object and array literal notation and JSON notation are that all property names in a JSON object must be double-quoted strings and that trailing commas in objects and arrays are forbidden. The main differences between standard number notation and JSON number notation are that in JSON leading zeroes are prohibited and the decimal point in a number must be followed by at least one digit. The main differences between standard string notation and JSON string notation are that in JSON only a limited set of characters may be escaped in strings, certain control characters are prohibited in strings, the Unicode line separator (U+2028) and paragraph separator (U+2029) characters are permitted, and that strings must be double-quoted.
The full JSON syntax is as follows:
JSON = null
or true or false
or JSONNumber
or JSONString
or JSONObject
or JSONArray
JSONNumber = - PositiveNumber
or PositiveNumber
PositiveNumber = DecimalNumber
or DecimalNumber . Digits
or DecimalNumber . Digits ExponentPart
or DecimalNumber ExponentPart
DecimalNumber = 0
or OneToNine Digits
ExponentPart = e Exponent
or E Exponent
Exponent = Digits
or + Digits
or - Digits
Digits = Digit
or Digits Digit
Digit = 0 through 9
OneToNine = 1 through 9
JSONString = ""
or " StringCharacters "
StringCharacters = StringCharacter
or StringCharacters StringCharacter
StringCharacter = any character
except " or \ or U+0000 through U+001F
or EscapeSequence
EscapeSequence = \" or \/ or \\ or \b or \f or \n or \r or \t
or \u HexDigit HexDigit HexDigit HexDigit
HexDigit = 0 through 9
or A through F
or a through f
JSONObject = { }
or { Members }
Members = JSONString : JSON
or Members , JSONString : JSON
JSONArray = [ ]
or [ ArrayElements ]
ArrayElements = JSON
or ArrayElements , JSON
Insignificant whitespace may be present anywhere except within a JSONNumber (numbers must contain no whitespace) or JSONString (where it is interpreted as the corresponding character in the string, or would cause an error). The tab character (U+0009), carriage return (U+000D), line feed (U+000A), and space (U+0020) characters are the only valid whitespace characters.
Description
The JSON object contains methods for parsing JSON and converting values to JSON. It can't be called or constructed, and aside from its two method properties it has no interesting functionality of its own.
Properties
Methods
Cross-browser compatibility
Based on Kangax's compat table.
| Feature | Firefox (Gecko) | Chrome | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | (Supported) | (Supported) | (Supported) | 10.5 | (Supported) |
| Feature | Firefox Mobile (Gecko) | Android | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | ? | ? | ? | ? | ? |
Object:__defineGetter__, __defineSetter__, hasOwnProperty, isPrototypeOf, __lookupGetter__, __lookupSetter__, __noSuchMethod__, propertyIsEnumerable, toLocaleString, toString, unwatch, valueOf, watch