// json2.js1// 2016-10-282// Public Domain.3// NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.4// See http://www.JSON.org/js.html5// This code should be minified before deployment.6// See http://javascript.crockford.com/jsmin.html78// USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO9// NOT CONTROL.1011// This file creates a global JSON object containing two methods: stringify12// and parse. This file provides the ES5 JSON capability to ES3 systems.13// If a project might run on IE8 or earlier, then this file should be included.14// This file does nothing on ES5 systems.1516// Create a JSON object only if one does not already exist. We create the17// methods in a closure to avoid creating global variables.1819if (typeof JSON !== "object") {20JSON = {};21}2223(function () {24"use strict";2526var rx_one = /^[\],:{}\s]*$/;27var rx_two = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g;28var rx_three = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;29var rx_four = /(?:^|:|,)(?:\s*\[)+/g;30var rx_escapable = /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;31var rx_dangerous = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;3233function f(n) {34// Format integers to have at least two digits.35return n < 1036? "0" + n37: n;38}3940function this_value() {41return this.valueOf();42}4344if (typeof Date.prototype.toJSON !== "function") {4546Date.prototype.toJSON = function () {4748return isFinite(this.valueOf())49? this.getUTCFullYear() + "-" +50f(this.getUTCMonth() + 1) + "-" +51f(this.getUTCDate()) + "T" +52f(this.getUTCHours()) + ":" +53f(this.getUTCMinutes()) + ":" +54f(this.getUTCSeconds()) + "Z"55: null;56};5758Boolean.prototype.toJSON = this_value;59Number.prototype.toJSON = this_value;60String.prototype.toJSON = this_value;61}6263var gap;64var indent;65var meta;66var rep;676869function quote(string) {7071// If the string contains no control characters, no quote characters, and no72// backslash characters, then we can safely slap some quotes around it.73// Otherwise we must also replace the offending characters with safe escape74// sequences.7576rx_escapable.lastIndex = 0;77return rx_escapable.test(string)78? "\"" + string.replace(rx_escapable, function (a) {79var c = meta[a];80return typeof c === "string"81? c82: "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4);83}) + "\""84: "\"" + string + "\"";85}868788function str(key, holder) {8990// Produce a string from holder[key].9192var i; // The loop counter.93var k; // The member key.94var v; // The member value.95var length;96var mind = gap;97var partial;98var value = holder[key];99100// If the value has a toJSON method, call it to obtain a replacement value.101102if (value && typeof value === "object" &&103typeof value.toJSON === "function") {104value = value.toJSON(key);105}106107// If we were called with a replacer function, then call the replacer to108// obtain a replacement value.109110if (typeof rep === "function") {111value = rep.call(holder, key, value);112}113114// What happens next depends on the value's type.115116switch (typeof value) {117case "string":118return quote(value);119120case "number":121122// JSON numbers must be finite. Encode non-finite numbers as null.123124return isFinite(value)125? String(value)126: "null";127128case "boolean":129case "null":130131// If the value is a boolean or null, convert it to a string. Note:132// typeof null does not produce "null". The case is included here in133// the remote chance that this gets fixed someday.134135return String(value);136137// If the type is "object", we might be dealing with an object or an array or138// null.139140case "object":141142// Due to a specification blunder in ECMAScript, typeof null is "object",143// so watch out for that case.144145if (!value) {146return "null";147}148149// Make an array to hold the partial results of stringifying this object value.150151gap += indent;152partial = [];153154// Is the value an array?155156if (Object.prototype.toString.apply(value) === "[object Array]") {157158// The value is an array. Stringify every element. Use null as a placeholder159// for non-JSON values.160161length = value.length;162for (i = 0; i < length; i += 1) {163partial[i] = str(i, value) || "null";164}165166// Join all of the elements together, separated with commas, and wrap them in167// brackets.168169v = partial.length === 0170? "[]"171: gap172? "[\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "]"173: "[" + partial.join(",") + "]";174gap = mind;175return v;176}177178// If the replacer is an array, use it to select the members to be stringified.179180if (rep && typeof rep === "object") {181length = rep.length;182for (i = 0; i < length; i += 1) {183if (typeof rep[i] === "string") {184k = rep[i];185v = str(k, value);186if (v) {187partial.push(quote(k) + (188gap189? ": "190: ":"191) + v);192}193}194}195} else {196197// Otherwise, iterate through all of the keys in the object.198199for (k in value) {200if (Object.prototype.hasOwnProperty.call(value, k)) {201v = str(k, value);202if (v) {203partial.push(quote(k) + (204gap205? ": "206: ":"207) + v);208}209}210}211}212213// Join all of the member texts together, separated with commas,214// and wrap them in braces.215216v = partial.length === 0217? "{}"218: gap219? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}"220: "{" + partial.join(",") + "}";221gap = mind;222return v;223}224}225226// If the JSON object does not yet have a stringify method, give it one.227228if (typeof JSON.stringify !== "function") {229meta = { // table of character substitutions230"\b": "\\b",231"\t": "\\t",232"\n": "\\n",233"\f": "\\f",234"\r": "\\r",235"\"": "\\\"",236"\\": "\\\\"237};238JSON.stringify = function (value, replacer, space) {239240// The stringify method takes a value and an optional replacer, and an optional241// space parameter, and returns a JSON text. The replacer can be a function242// that can replace values, or an array of strings that will select the keys.243// A default replacer method can be provided. Use of the space parameter can244// produce text that is more easily readable.245246var i;247gap = "";248indent = "";249250// If the space parameter is a number, make an indent string containing that251// many spaces.252253if (typeof space === "number") {254for (i = 0; i < space; i += 1) {255indent += " ";256}257258// If the space parameter is a string, it will be used as the indent string.259260} else if (typeof space === "string") {261indent = space;262}263264// If there is a replacer, it must be a function or an array.265// Otherwise, throw an error.266267rep = replacer;268if (replacer && typeof replacer !== "function" &&269(typeof replacer !== "object" ||270typeof replacer.length !== "number")) {271throw new Error("JSON.stringify");272}273274// Make a fake root object containing our value under the key of "".275// Return the result of stringifying the value.276277return str("", {"": value});278};279}280281282// If the JSON object does not yet have a parse method, give it one.283284if (typeof JSON.parse !== "function") {285JSON.parse = function (text, reviver) {286287// The parse method takes a text and an optional reviver function, and returns288// a JavaScript value if the text is a valid JSON text.289290var j;291292function walk(holder, key) {293294// The walk method is used to recursively walk the resulting structure so295// that modifications can be made.296297var k;298var v;299var value = holder[key];300if (value && typeof value === "object") {301for (k in value) {302if (Object.prototype.hasOwnProperty.call(value, k)) {303v = walk(value, k);304if (v !== undefined) {305value[k] = v;306} else {307delete value[k];308}309}310}311}312return reviver.call(holder, key, value);313}314315316// Parsing happens in four stages. In the first stage, we replace certain317// Unicode characters with escape sequences. JavaScript handles many characters318// incorrectly, either silently deleting them, or treating them as line endings.319320text = String(text);321rx_dangerous.lastIndex = 0;322if (rx_dangerous.test(text)) {323text = text.replace(rx_dangerous, function (a) {324return "\\u" +325("0000" + a.charCodeAt(0).toString(16)).slice(-4);326});327}328329// In the second stage, we run the text against regular expressions that look330// for non-JSON patterns. We are especially concerned with "()" and "new"331// because they can cause invocation, and "=" because it can cause mutation.332// But just to be safe, we want to reject all unexpected forms.333334// We split the second stage into 4 regexp operations in order to work around335// crippling inefficiencies in IE's and Safari's regexp engines. First we336// replace the JSON backslash pairs with "@" (a non-JSON character). Second, we337// replace all simple value tokens with "]" characters. Third, we delete all338// open brackets that follow a colon or comma or that begin the text. Finally,339// we look to see that the remaining characters are only whitespace or "]" or340// "," or ":" or "{" or "}". If that is so, then the text is safe for eval.341342if (343rx_one.test(344text345.replace(rx_two, "@")346.replace(rx_three, "]")347.replace(rx_four, "")348)349) {350351// In the third stage we use the eval function to compile the text into a352// JavaScript structure. The "{" operator is subject to a syntactic ambiguity353// in JavaScript: it can begin a block or an object literal. We wrap the text354// in parens to eliminate the ambiguity.355356j = eval("(" + text + ")");357358// In the optional fourth stage, we recursively walk the new structure, passing359// each name/value pair to a reviver function for possible transformation.360361return (typeof reviver === "function")362? walk({"": j}, "")363: j;364}365366// If the text is not JSON parseable, then a SyntaxError is thrown.367368throw new SyntaxError("JSON.parse");369};370}371}());372373374