< draft-crockford-jsonorg-json-01.txt   draft-crockford-jsonorg-json-02.txt >
JSON D. Crockford JavaScript Object Notation D. Crockford
Internet Draft JSON.org Internet Draft JSON.org
draft-crockford-jsonorg-json-01.txt February, 2006 draft-crockford-jsonorg-json-02.txt February, 2006
Intended status: Informational Intended status: Informational
Expires: June 10, 2006 Expires: June 10, 2006
JSON JavaScript Object Notation
Status of this Memo Status of this Memo
This document may not be modified, and derivative works of it This document may not be modified, and derivative works of it
may not be created, except to publish it as an RFC and to may not be created, except to publish it as an RFC and to
translate it into languages other than English. translate it into languages other than English.
By submitting this Internet-Draft, each author represents that any By submitting this Internet-Draft, each author represents that any
applicable patent or other IPR claims of which he or she is aware applicable patent or other IPR claims of which he or she is aware
have been or will be disclosed, and any of which he or she becomes have been or will be disclosed, and any of which he or she becomes
skipping to change at line 54 skipping to change at line 54
JSON (JavaScript Object Notation) is a light-weight, text-based, JSON (JavaScript Object Notation) is a light-weight, text-based,
language-independent, data interchange format. It was derived from language-independent, data interchange format. It was derived from
the ECMAScript Programming Language Standard. JSON defines a small the ECMAScript Programming Language Standard. JSON defines a small
set of formatting rules for the portable representation of structured set of formatting rules for the portable representation of structured
data. data.
Conventions used in this document Conventions used in this document
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
document are to be interpreted as described in RFC-2119. document are to be interpreted as described in [RFC-2119].
The syntax rules in this document are to be interpreted as The grammatical rules in this document are to be interpreted as
described in RFC-2234. described in [RFC-4234].
1. Introduction 1. Introduction
JSON, or JavaScript Object Notation, is a text format for the JSON, or JavaScript Object Notation, is a text format for the
serialization of structured data. It is derived from the object serialization of structured data. It is derived from the object
literals of JavaScript, as defined in the ECMAScript literals of JavaScript, as defined in the ECMAScript
Programming Language Standard [ECMA]. Programming Language Standard [ECMA].
JSON can represent four primitive types (strings, numbers, booleans, JSON can represent four primitive types (strings, numbers, booleans,
and null) and two structured types (objects and arrays). and null) and two structured types (objects and arrays).
skipping to change at line 94 skipping to change at line 94
A JSON text is a sequence of tokens. The set of tokens includes six A JSON text is a sequence of tokens. The set of tokens includes six
structural characters, strings, numbers, and three literal names. structural characters, strings, numbers, and three literal names.
A JSON text is a serialized object or array. A JSON text is a serialized object or array.
JSON-text = object / array JSON-text = object / array
These are the six structural characters: These are the six structural characters:
begin-array = %x5B ; [ left square bracket begin-array = ws %x5B ws ; [ left square bracket
begin-object = %x7B ; { left curly bracket
end-array = %x5D ; ] right square bracket
end-object = %x7D ; } right curly bracket begin-object = ws %x7B ws ; { left curly bracket
name-separator = %x3A ; : colon end-array = ws %x5D ws ; ] right square bracket
value-separator = %x2C ; , comma end-object = ws %x7D ws ; } right curly bracket
2.1. Whitespace name-separator = ws %x3A ws ; : colon
The tokens MAY be separated by any combination of these value-separator = ws %x2C ws ; , comma
insignificant whitespace characters:
space U+0020 Space Insignificant whitespace is allowed before or after any of the six
HT U+0009 Horizontal tab structural characters.
LF U+000A Line feed or New line
CR U+000D Carriage return
Insignificant whitespace MUST NOT be placed within a ws = *(
multicharacter token (a literal name, number, or string). %x20 / ; Space
A space character in a string is significant. %x09 / ; Horizontal tab
%x0A / ; Line feed or New line
%x0D ; Carriage return
)
2.2. Values 2.1. Values
A JSON value MUST be a object, array, number, or string, or one of A JSON value MUST be a object, array, number, or string, or one of
the three literal names: the three literal names:
false null true false null true
The literal names MUST be in lower case. No other literal names The literal names MUST be in lower case. No other literal names
are allowed. are allowed.
value = false / null / true / object / array / number / string value = false / null / true / object / array / number / string
false = %x66.61.6c.73.65 ; false false = %x66.61.6c.73.65 ; false
null = %x6e.75.6c.6c ; null null = %x6e.75.6c.6c ; null
true = %x74.72.75.65 ; true true = %x74.72.75.65 ; true
2.3. Objects 2.2. Objects
An object structure is represented as a pair of curly brackets An object structure is represented as a pair of curly brackets
surrounding zero or more name/value pairs (or members). A name is surrounding zero or more name/value pairs (or members). A name is
a string. A single colon comes after each name, separating the a string. A single colon comes after each name, separating the
name from the value. A single comma separates a value from a name from the value. A single comma separates a value from a
following name. following name.
object = begin-object [ member *( value-separator member ) ] object = begin-object [ member *( value-separator member ) ]
end-object end-object
member = string name-separator value member = string name-separator value
2.4. Arrays 2.3. Arrays
An array structure is represented as square brackets surrounding An array structure is represented as square brackets surrounding
zero or more values (or elements). Elements are separated by zero or more values (or elements). Elements are separated by
commas. commas.
array = begin-array [ value *( value-separator value ) ] array = begin-array [ value *( value-separator value ) ]
end-array end-array
2.5. Numbers 2.4. Numbers
The representation of numbers is similar to that used in most The representation of numbers is similar to that used in most
programming languages. A number contains an integer component programming languages. A number contains an integer component
which may be prefixed with an optional minus sign, which may be which may be prefixed with an optional minus sign, which may be
followed by a fraction part and/or an exponent part. followed by a fraction part and/or an exponent part.
Octal and hex forms are not allowed. Leading zeros are not Octal and hex forms are not allowed. Leading zeros are not
allowed. allowed.
A fraction part is a decimal point followed by one or more digits. A fraction part is a decimal point followed by one or more digits.
skipping to change at line 199 skipping to change at line 195
frac = decimal-point 1*DIGIT frac = decimal-point 1*DIGIT
int = zero / ( digit1-9 *DIGIT ) int = zero / ( digit1-9 *DIGIT )
minus = %x2D ; - minus = %x2D ; -
plus = %x2B ; + plus = %x2B ; +
zero = %x30 ; 0 zero = %x30 ; 0
2.6. Strings 2.5. Strings
The representation of strings is similar to conventions used in The representation of strings is similar to conventions used in
the C family of programming languages. A string begins and ends the C family of programming languages. A string begins and ends
with quotation marks. All Unicode characters may be placed within with quotation marks. All Unicode characters may be placed within
the quotation marks except for the characters which must be the quotation marks except for the characters which must be
escaped: quotation mark, reverse solidus, and the control escaped: quotation mark, reverse solidus, and the control
characters (U+0000 through U+001F). characters (U+0000 through U+001F).
Any character may be escaped. If the character is in the Basic Any character may be escaped. If the character is in the Basic
Multilingual Plane (U+0000 through U+FFFF) then it may be Multilingual Plane (U+0000 through U+FFFF) then it may be
skipping to change at line 254 skipping to change at line 250
quotation-mark = %x22 ; " quotation-mark = %x22 ; "
unescaped = %x20-21 / %x23-5B / %x5D-10FFFF unescaped = %x20-21 / %x23-5B / %x5D-10FFFF
3. Encoding 3. Encoding
JSON text SHOULD be encoded in Unicode. The default encoding is JSON text SHOULD be encoded in Unicode. The default encoding is
UTF-8. UTF-8.
Since the first two characters of a JSON text will always be ASCII Since the first two characters of a JSON text will always be ASCII
characters, it is possible to determine if an octet stream is characters [RFC-0020], it is possible to determine if an octet stream
UTF-8, UTF-16 (BE or LE), or UTF-32 (BE or LE) by looking at the is UTF-8, UTF-16 (BE or LE), or UTF-32 (BE or LE) by looking at the
pattern of nulls in the first four octets. pattern of nulls in the first four octets.
00 00 00 xx UTF-32BE 00 00 00 xx UTF-32BE
00 xx 00 xx UTF-16BE 00 xx 00 xx UTF-16BE
xx 00 00 00 UTF-32LE xx 00 00 00 UTF-32LE
xx 00 xx 00 UTF-16LE xx 00 xx 00 UTF-16LE
xx xx xx xx UTF-8 xx xx xx xx UTF-8
4. Parsers 4. Parsers
skipping to change at line 283 skipping to change at line 279
An implementation may set limits on the length and character contents An implementation may set limits on the length and character contents
of strings. of strings.
5. Generators 5. Generators
A JSON generator produces JSON text. The resulting text MUST A JSON generator produces JSON text. The resulting text MUST
strictly conform to the JSON grammar. strictly conform to the JSON grammar.
6. IANA Considerations 6. IANA Considerations
The MIME media type for JSON text is text/json. The MIME media type for JSON text is text/json. See section 7.
7. Security Considerations 7. Registration Template
To: ietf-types@iana.org
Subject: Registration of media type text/json
Type name: text
Subtype name: json
Required parameters: n/a
Optional parameters: n/a
Encoding considerations: 8bit
Security considerations: See section 9 below.
Interoperability considerations: n/a
Published specification: RFC-XXXX
Applications that use this media type: See http://www.JSON.org.
Additional information:
Magic number(s): n/a
File extension(s): .json
Macintosh file type code(s): TEXT
Person & email address to contact for further information:
Douglas Crockford
douglas@crockford.com
Intended usage: COMMON
Restrictions on usage: none
Author: Douglas Crockford
Change controller: Douglas Crockford
8. Security Considerations
Generally there are security issues with scripting languages. JSON Generally there are security issues with scripting languages. JSON
is a subset of JavaScript, but it is a safe subset that excludes is a subset of JavaScript, but it is a safe subset that excludes
assignment and invocation. assignment and invocation.
A JSON text can be safely passed into JavaScript's eval() function A JSON text can be safely passed into JavaScript's eval() function
(which compiles and executes a string) if all of the characters not (which compiles and executes a string) if all of the characters not
enclosed in strings are in the set of characters which form JSON enclosed in strings are in the set of characters which form JSON
tokens. This can be quickly determined in JavaScript with two tokens. This can be quickly determined in JavaScript with two
regular expressions and calls to the test and replace methods. regular expressions and calls to the test and replace methods.
var my_JSON_object = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test( var my_JSON_object = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
text.replace(/"(\\.|[^"\\])*"/g, ''))) && text.replace(/"(\\.|[^"\\])*"/g, ''))) &&
eval('(' + text + ')'); eval('(' + text + ')');
8. References 9. References
8.1 Normative References 9.1 Normative References
[ECMA] European Computer Manufacturers Association, "ECMAScript [ECMA] European Computer Manufacturers Association, "ECMAScript
Language Specification 3rd Edition", December 1999, Language Specification 3rd Edition", December 1999,
<http://www.ecma-international.org/publications/files/ <http://www.ecma-international.org/publications/files/
ecma-st/ECMA-262.pdf>. ecma-st/ECMA-262.pdf>.
[RFC-0020] Cerf, V., "ASCII format for Network Interchange",
RFC 0020, October 16, 1969.
[RFC-2119] Bradner, S., "Key words for use in RFCs to Indicate
Requirement Levels", RFC 2119, March 1997.
[RFC-4234] Crocker, D., "Augmented BNF for Syntax Specifications:
ABNF", RFC 4234, October 2005.
[UNICODE] The Unicode Consortium, "The Unicode Standard [UNICODE] The Unicode Consortium, "The Unicode Standard
Version 4.0", 2003, Version 4.0", 2003,
<http://www.unicode.org/versions/Unicode4.1.0/>. <http://www.unicode.org/versions/Unicode4.1.0/>.
Author's Address Author's Address
Douglas Crockford Douglas Crockford
JSON.org JSON.org
Contact Email: douglas@crockford.com Contact Email: douglas@crockford.com
 End of changes. 25 change blocks. 
36 lines changed or deleted 82 lines changed or added

This html diff was produced by rfcdiff 1.48. The latest version is available from http://tools.ietf.org/tools/rfcdiff/