Project link
* https://github.com/douglascrockford/JSON-js
File link
* https://github.com/douglascrockford/JSON-js/blob/
c98948ae19/json2.js
Change-Id: Ifeb41140c13718162d1c0bd7a5a815acaf7bfd56
==== External libraries ====
* Update es5-shim from v4.0.0 to v4.1.5.
==== External libraries ====
* Update es5-shim from v4.0.0 to v4.1.5.
+* Update json2 from revision 2014-02-04 to 2015-05-03.
=== Bug fixes in 1.26 ===
* (bug 51283) load.php sometimes sends 304 response without full headers
=== Bug fixes in 1.26 ===
* (bug 51283) load.php sometimes sends 304 response without full headers
This file creates a global JSON object containing two methods: stringify
This file creates a global JSON object containing two methods: stringify
+ and parse. This file is provides the ES5 JSON capability to ES3 systems.
+ If a project might run on IE8 or earlier, then this file should be included.
+ This file does nothing on ES5 systems.
JSON.stringify(value, replacer, space)
value any JavaScript value, usually an object or array.
JSON.stringify(value, replacer, space)
value any JavaScript value, usually an object or array.
Date.prototype.toJSON = function (key) {
function f(n) {
// Format integers to have at least two digits.
Date.prototype.toJSON = function (key) {
function f(n) {
// Format integers to have at least two digits.
- return n < 10 ? '0' + n : n;
+ return n < 10
+ ? '0' + n
+ : n;
}
return this.getUTCFullYear() + '-' +
}
return this.getUTCFullYear() + '-' +
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
text = JSON.stringify([new Date()], function (key, value) {
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
text = JSON.stringify([new Date()], function (key, value) {
- return this[key] instanceof Date ?
- 'Date(' + this[key] + ')' : value;
+ return this[key] instanceof Date
+ ? 'Date(' + this[key] + ')'
+ : value;
});
// text is '["Date(---current time---)"]'
});
// text is '["Date(---current time---)"]'
-/*jslint evil: true, regexp: true */
+/*jslint
+ eval, for, this
+*/
-/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
- call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
+/*property
+ JSON, apply, call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
lastIndex, length, parse, prototype, push, replace, slice, stringify,
test, toJSON, toString, valueOf
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
lastIndex, length, parse, prototype, push, replace, slice, stringify,
test, toJSON, toString, valueOf
(function () {
'use strict';
(function () {
'use strict';
+
+ var rx_one = /^[\],:{}\s]*$/,
+ rx_two = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,
+ rx_three = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
+ rx_four = /(?:^|:|,)(?:\s*\[)+/g,
+ rx_escapable = /[\\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
+ rx_dangerous = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
function f(n) {
// Format integers to have at least two digits.
function f(n) {
// Format integers to have at least two digits.
- return n < 10 ? '0' + n : n;
+ return n < 10
+ ? '0' + n
+ : n;
+ }
+
+ function this_value() {
+ return this.valueOf();
}
if (typeof Date.prototype.toJSON !== 'function') {
}
if (typeof Date.prototype.toJSON !== 'function') {
Date.prototype.toJSON = function () {
return isFinite(this.valueOf())
Date.prototype.toJSON = function () {
return isFinite(this.valueOf())
- ? this.getUTCFullYear() + '-' +
- f(this.getUTCMonth() + 1) + '-' +
- f(this.getUTCDate()) + 'T' +
- f(this.getUTCHours()) + ':' +
- f(this.getUTCMinutes()) + ':' +
- f(this.getUTCSeconds()) + 'Z'
+ ? this.getUTCFullYear() + '-' +
+ f(this.getUTCMonth() + 1) + '-' +
+ f(this.getUTCDate()) + 'T' +
+ f(this.getUTCHours()) + ':' +
+ f(this.getUTCMinutes()) + ':' +
+ f(this.getUTCSeconds()) + 'Z'
- String.prototype.toJSON =
- Number.prototype.toJSON =
- Boolean.prototype.toJSON = function () {
- return this.valueOf();
- };
+ Boolean.prototype.toJSON = this_value;
+ Number.prototype.toJSON = this_value;
+ String.prototype.toJSON = this_value;
- var cx,
- escapable,
- gap,
// Otherwise we must also replace the offending characters with safe escape
// sequences.
// Otherwise we must also replace the offending characters with safe escape
// sequences.
- escapable.lastIndex = 0;
- return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
- var c = meta[a];
- return typeof c === 'string'
- ? c
- : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
- }) + '"' : '"' + string + '"';
+ rx_escapable.lastIndex = 0;
+ return rx_escapable.test(string)
+ ? '"' + string.replace(rx_escapable, function (a) {
+ var c = meta[a];
+ return typeof c === 'string'
+ ? c
+ : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
+ }) + '"'
+ : '"' + string + '"';
// JSON numbers must be finite. Encode non-finite numbers as null.
// JSON numbers must be finite. Encode non-finite numbers as null.
- return isFinite(value) ? String(value) : 'null';
+ return isFinite(value)
+ ? String(value)
+ : 'null';
case 'boolean':
case 'null':
case 'boolean':
case 'null':
v = partial.length === 0
? '[]'
: gap
v = partial.length === 0
? '[]'
: gap
- ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
- : '[' + partial.join(',') + ']';
+ ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
+ : '[' + partial.join(',') + ']';
k = rep[i];
v = str(k, value);
if (v) {
k = rep[i];
v = str(k, value);
if (v) {
- partial.push(quote(k) + (gap ? ': ' : ':') + v);
+ partial.push(quote(k) + (
+ gap
+ ? ': '
+ : ':'
+ ) + v);
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = str(k, value);
if (v) {
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = str(k, value);
if (v) {
- partial.push(quote(k) + (gap ? ': ' : ':') + v);
+ partial.push(quote(k) + (
+ gap
+ ? ': '
+ : ':'
+ ) + v);
v = partial.length === 0
? '{}'
: gap
v = partial.length === 0
? '{}'
: gap
- ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
- : '{' + partial.join(',') + '}';
+ ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
+ : '{' + partial.join(',') + '}';
// If the JSON object does not yet have a stringify method, give it one.
if (typeof JSON.stringify !== 'function') {
// If the JSON object does not yet have a stringify method, give it one.
if (typeof JSON.stringify !== 'function') {
- escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
meta = { // table of character substitutions
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
meta = { // table of character substitutions
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'\\': '\\\\'
};
JSON.stringify = function (value, replacer, space) {
'\\': '\\\\'
};
JSON.stringify = function (value, replacer, space) {
// If the JSON object does not yet have a parse method, give it one.
if (typeof JSON.parse !== 'function') {
// If the JSON object does not yet have a parse method, give it one.
if (typeof JSON.parse !== 'function') {
- cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
JSON.parse = function (text, reviver) {
// The parse method takes a text and an optional reviver function, and returns
JSON.parse = function (text, reviver) {
// The parse method takes a text and an optional reviver function, and returns
// incorrectly, either silently deleting them, or treating them as line endings.
text = String(text);
// incorrectly, either silently deleting them, or treating them as line endings.
text = String(text);
- cx.lastIndex = 0;
- if (cx.test(text)) {
- text = text.replace(cx, function (a) {
+ rx_dangerous.lastIndex = 0;
+ if (rx_dangerous.test(text)) {
+ text = text.replace(rx_dangerous, function (a) {
- ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
+ ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
// we look to see that the remaining characters are only whitespace or ']' or
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
// we look to see that the remaining characters are only whitespace or ']' or
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
- if (/^[\],:{}\s]*$/
- .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
- .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
- .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
+ if (
+ rx_one.test(
+ text
+ .replace(rx_two, '@')
+ .replace(rx_three, ']')
+ .replace(rx_four, '')
+ )
+ ) {
// In the third stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
// In the third stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity