< draft-crockford-jsonorg-json-02.txt   draft-crockford-jsonorg-json-03.txt >
JavaScript Object Notation D. Crockford JavaScript Object Notation (JSON) D. Crockford
Internet Draft JSON.org Internet Draft JSON.org
draft-crockford-jsonorg-json-02.txt February, 2006 draft-crockford-jsonorg-json-03.txt February, 2006
Intended status: Informational Intended status: Informational
Expires: June 10, 2006 Expires: June 10, 2006
JavaScript Object Notation JavaScript Object Notation (JSON)
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 44 skipping to change at line 44
http://www.ietf.org/shadow.html. http://www.ietf.org/shadow.html.
This Internet Draft will expire on June 10, 2006. This Internet Draft will expire on June 10, 2006.
Copyright Notice Copyright Notice
Copyright (C) The Internet Society (2006). Copyright (C) The Internet Society (2006).
Abstract Abstract
JSON (JavaScript Object Notation) is a light-weight, text-based, JavaScript Object Notation (JSON) 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 grammatical rules in this document are to be interpreted as The grammatical rules in this document are to be interpreted as
described in [RFC-4234]. described in [RFC-4234].
1. Introduction 1. Introduction
JSON, or JavaScript Object Notation, is a text format for the JavaScript Object Notation (JSON) 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, Third Edition [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).
A string is a sequence of zero or more Unicode characters. A string is a sequence of zero or more Unicode characters [UNICODE].
An object is an unordered collection of zero or more name/value An object is an unordered collection of zero or more name/value
pairs, where a name is a string, and a value is a string, number, pairs, where a name is a string, and a value is a string, number,
boolean, null, object, or array. boolean, null, object, or array.
An array is an ordered sequence of zero or more values. An array is an ordered sequence of zero or more values.
The terms "object" and "array" come from the conventions of The terms "object" and "array" come from the conventions of
JavaScript. JavaScript.
skipping to change at line 279 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. See section 7. The MIME media type for JSON text is text/json.
7. Registration Template
To: ietf-types@iana.org
Subject: Registration of media type text/json
Type name: text Type name: text
Subtype name: json Subtype name: json
Required parameters: n/a Required parameters: n/a
Optional parameters: n/a Optional parameters: n/a
Encoding considerations: 8bit Encoding considerations: 8bit
Security considerations: See section 9 below. Security considerations:
Generally there are security issues with scripting languages.
JSON is a subset of JavaScript, but it is a safe subset that
excludes assignment and invocation.
A JSON text can be safely passed into JavaScript's eval()
function (which compiles and executes a string) if all of the
characters not enclosed in strings are in the set of characters
which form JSON tokens. This can be quickly determined in
JavaScript with two regular expressions and calls to the test and
replace methods.
var my_JSON_object = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
text.replace(/"(\\.|[^"\\])*"/g, ''))) &&
eval('(' + text + ')');
Interoperability considerations: n/a Interoperability considerations: n/a
Published specification: RFC-XXXX Published specification: RFC-XXXX
Applications that use this media type: See http://www.JSON.org. Applications that use this media type:
JSON has been used to exchange data between applications written
in all of these programming languages: ActionScript, C, C#,
ColdFusion, Common Lisp, E, Erlang, Java, JavaScript, Lua,
Objective CAML, Perl, PHP, Python, Rebol, Ruby, and Scheme.
Additional information: Additional information:
Magic number(s): n/a Magic number(s): n/a
File extension(s): .json File extension(s): .json
Macintosh file type code(s): TEXT Macintosh file type code(s): TEXT
Person & email address to contact for further information: Person & email address to contact for further information:
Douglas Crockford Douglas Crockford
douglas@crockford.com douglas@crockford.com
Intended usage: COMMON Intended usage: COMMON
Restrictions on usage: none Restrictions on usage: none
Author: Douglas Crockford Author:
Douglas Crockford
douglas@crockford.com
Change controller: Douglas Crockford Change controller:
Douglas Crockford
douglas@crockford.com
8. Security Considerations 7. Security Considerations
Generally there are security issues with scripting languages. JSON See Security considerations in Section 6.
is a subset of JavaScript, but it is a safe subset that excludes
assignment and invocation.
A JSON text can be safely passed into JavaScript's eval() function 8. Examples
(which compiles and executes a string) if all of the characters not
enclosed in strings are in the set of characters which form JSON
tokens. This can be quickly determined in JavaScript with two
regular expressions and calls to the test and replace methods.
var my_JSON_object = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test( This is a JSON object:
text.replace(/"(\\.|[^"\\])*"/g, ''))) &&
eval('(' + text + ')'); {
"Image": {
"Width": 800,
"Height": 600,
"Title": "View from 15th Floor",
"Thumbnail": {
"Url": "http://scd.mm-b1.yimg.com/image/481989943",
"Height": 125,
"Width": "100"
},
"IDs": [116, 943, 234, 38793]
}
}
Its Image member is an object whose Thumbnail member is an object
and whose IDs member is an array of numbers.
This is a JSON array containing two objects:
[
{
"precision": "zip",
"Latitude": 37.7668,
"Longitude": -122.3959,
"Address": "",
"City": "SAN FRANCISCO",
"State": "CA",
"Zip": "94107",
"Country": "US"
},
{
"precision": "zip",
"Latitude": 37.371991,
"Longitude": -122.026020,
"Address": "",
"City": "SUNNYVALE",
"State": "CA",
"Zip": "94085",
"Country": "US"
}
]
9. References 9. References
9.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>.
 End of changes. 17 change blocks. 
32 lines changed or deleted 85 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/