

JSON 3 is {\bfseries{deprecated}} and {\bfseries{no longer maintained}}. Please don\textquotesingle{}t use it in new projects, and migrate existing projects to use the native {\ttfamily JSON.\+parse} and {\ttfamily JSON.\+stringify} instead.

Thanks to everyone who contributed patches or found it useful! ❤️\hypertarget{md_sfcode_node_modules_json3_README_autotoc_md14347}{}\doxysection{JSON 3}\label{md_sfcode_node_modules_json3_README_autotoc_md14347}
\href{http://unmaintained.tech/}{\texttt{ }}

{\bfseries{JSON 3}} was a JSON polyfill for older Java\+Script platforms.\hypertarget{md_sfcode_node_modules_json3_README_autotoc_md14348}{}\doxysubsection{About}\label{md_sfcode_node_modules_json3_README_autotoc_md14348}
\href{http://json.org/}{\texttt{ JSON}} is a language-\/independent data interchange format based on a loose subset of the Java\+Script grammar. Originally popularized by \href{http://www.crockford.com/}{\texttt{ Douglas Crockford}}, the format was standardized in the \href{http://es5.github.io/}{\texttt{ fifth edition}} of the ECMAScript specification. The 5.\+1 edition, ratified in June 2011, incorporates several modifications to the grammar pertaining to the serialization of dates.

JSON 3 exposes two functions\+: {\ttfamily stringify()} for \href{https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/JSON/stringify}{\texttt{ serializing}} a Java\+Script value to JSON, and {\ttfamily parse()} for \href{https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/JSON/parse}{\texttt{ producing}} a Java\+Script value from a JSON source string. The JSON 3 parser uses recursive descent instead of {\ttfamily eval} and regular expressions, which makes it slower on older platforms compared to \href{http://json.org/js}{\texttt{ JSON 2}}. The functions behave exactly as described in the ECMAScript spec, {\bfseries{except}} for the date serialization discrepancy noted below.

The project is \href{http://git.io/json3}{\texttt{ hosted on Git\+Hub}}, along with the \href{http://bestiejs.github.io/json3/test/test_browser.html}{\texttt{ unit tests}}. It is part of the \href{https://github.com/bestiejs}{\texttt{ Bestie\+JS}} family, a collection of best-\/in-\/class Java\+Script libraries that promote cross-\/platform support, specification precedents, unit testing, and plenty of documentation.\hypertarget{md_sfcode_node_modules_json3_README_autotoc_md14349}{}\doxysubsection{Date Serialization}\label{md_sfcode_node_modules_json3_README_autotoc_md14349}
{\bfseries{JSON 3 deviates from the specification in one important way}}\+: it does not define {\ttfamily Date\#to\+ISOString()} or {\ttfamily Date\#to\+JSON()}. This preserves Common\+JS compatibility and avoids polluting native prototypes. Instead, date serialization is performed internally by the {\ttfamily stringify()} implementation\+: if a date object does not define a custom {\ttfamily to\+JSON()} method, it is serialized as a \href{http://es5.github.com/\#x15.9.1.15}{\texttt{ simplified ISO 8601 date-\/time string}}.

{\bfseries{Several native {\ttfamily Date\#to\+JSON()} implementations produce date time strings that do {\itshape not} conform to the grammar outlined in the spec}}. In these environments, JSON 3 will override the native {\ttfamily stringify()} implementation. There is an \href{https://github.com/bestiejs/json3/issues/73}{\texttt{ issue}} on file to make these tests less strict.

Portions of the date serialization code are adapted from the \href{https://github.com/Yaffle/date-shim}{\texttt{ {\ttfamily date-\/shim}}} project.\hypertarget{md_sfcode_node_modules_json3_README_autotoc_md14350}{}\doxysection{Usage}\label{md_sfcode_node_modules_json3_README_autotoc_md14350}
\hypertarget{md_sfcode_node_modules_json3_README_autotoc_md14351}{}\doxysubsection{Web Browsers}\label{md_sfcode_node_modules_json3_README_autotoc_md14351}
\begin{DoxyVerb}<script src="//cdnjs.cloudflare.com/ajax/libs/json3/3.3.2/json3.min.js"></script>
<script>
  JSON.stringify({"Hello": 123});
  // => '{"Hello":123}'
  JSON.parse("[[1, 2, 3], 1, 2, 3, 4]", function (key, value) {
    if (typeof value == "number") {
      value = value % 2 ? "Odd" : "Even";
    }
    return value;
  });
  // => [["Odd", "Even", "Odd"], "Odd", "Even", "Odd", "Even"]
</script>
\end{DoxyVerb}
 {\bfseries{When used in a web browser}}, JSON 3 exposes an additional {\ttfamily JSON3} object containing the {\ttfamily no\+Conflict()} and {\ttfamily run\+In\+Context()} functions, as well as aliases to the {\ttfamily stringify()} and {\ttfamily parse()} functions.\hypertarget{md_sfcode_node_modules_json3_README_autotoc_md14352}{}\doxysubsubsection{$<$tt$>$no\+Conflict$<$/tt$>$ and $<$tt$>$run\+In\+Context$<$/tt$>$}\label{md_sfcode_node_modules_json3_README_autotoc_md14352}

\begin{DoxyItemize}
\item {\ttfamily JSON3.\+no\+Conflict()} restores the original value of the global {\ttfamily JSON} object and returns a reference to the {\ttfamily JSON3} object.
\item {\ttfamily JSON3.\+run\+In\+Context(\mbox{[}context, exports\mbox{]})} initializes JSON 3 using the given {\ttfamily context} object (e.\+g., {\ttfamily window}, {\ttfamily global}, etc.), or the global object if omitted. If an {\ttfamily exports} object is specified, the {\ttfamily stringify()}, {\ttfamily parse()}, and {\ttfamily run\+In\+Context()} functions will be attached to it instead of a new object.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_json3_README_autotoc_md14353}{}\doxysubsubsection{Asynchronous Module Loaders}\label{md_sfcode_node_modules_json3_README_autotoc_md14353}
JSON 3 is defined as an \href{https://github.com/amdjs/amdjs-api/wiki/AMD\#define-function-}{\texttt{ anonymous module}} for compatibility with \href{http://requirejs.org/}{\texttt{ Require\+JS}}, \href{https://github.com/cujojs/curl}{\texttt{ {\ttfamily curl.\+js}}}, and other asynchronous module loaders. \begin{DoxyVerb}<script src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.js"></script>
<script>
  require({
    "paths": {
      "json3": "./path/to/json3"
    }
  }, ["json3"], function (JSON) {
    JSON.parse("[1, 2, 3]");
    // => [1, 2, 3]
  });
</script>
\end{DoxyVerb}
 To avoid issues with third-\/party scripts, {\bfseries{JSON 3 is exported to the global scope even when used with a module loader}}. If this behavior is undesired, {\ttfamily JSON3.\+no\+Conflict()} can be used to restore the global {\ttfamily JSON} object to its original value.

{\bfseries{Note\+:}} If you intend to use JSON3 alongside another module, {\bfseries{please do not simply concatenate these modules together}}, as that would cause multiple {\ttfamily define} calls in one script, resulting in errors in AMD loaders. The {\ttfamily r.\+js} build optimizer can be used instead if you need a single compressed file for production.\hypertarget{md_sfcode_node_modules_json3_README_autotoc_md14354}{}\doxysubsection{Common\+JS Environments}\label{md_sfcode_node_modules_json3_README_autotoc_md14354}
\begin{DoxyVerb}var JSON3 = require("./path/to/json3");
JSON3.parse("[1, 2, 3]");
// => [1, 2, 3]
\end{DoxyVerb}
 \hypertarget{md_sfcode_node_modules_json3_README_autotoc_md14355}{}\doxysubsection{Java\+Script Engines}\label{md_sfcode_node_modules_json3_README_autotoc_md14355}
\begin{DoxyVerb}load("path/to/json3.js");
JSON.stringify({"Hello": 123, "Good-bye": 456}, ["Hello"], "\t");
// => '{\n\t"Hello": 123\n}'
\end{DoxyVerb}
 \hypertarget{md_sfcode_node_modules_json3_README_autotoc_md14356}{}\doxysection{Compatibility}\label{md_sfcode_node_modules_json3_README_autotoc_md14356}
JSON 3 has been {\bfseries{tested}} with the following web browsers, Common\+JS environments, and Java\+Script engines.\hypertarget{md_sfcode_node_modules_json3_README_autotoc_md14357}{}\doxysubsection{Web Browsers}\label{md_sfcode_node_modules_json3_README_autotoc_md14357}

\begin{DoxyItemize}
\item Windows \href{http://windows.microsoft.com/en-us/internet-explorer/download-ie}{\texttt{ Internet Explorer}}, version 6.\+0 and higher
\item Google \href{http://www.google.com/chrome}{\texttt{ Chrome}}, version 19.\+0 and higher
\item Mozilla \href{https://www.mozilla.org/en-US/firefox/new/}{\texttt{ Firefox}}, version 2.\+0 and higher
\item Apple \href{http://www.apple.com/safari/}{\texttt{ Safari}}, version 3.\+0 and higher
\item \href{http://www.opera.com/}{\texttt{ Opera}} 8.\+54 and higher
\item \href{http://www.seamonkey-project.org/}{\texttt{ Sea\+Monkey}} 1.\+0 and higher
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_json3_README_autotoc_md14358}{}\doxysubsection{Common\+JS Environments}\label{md_sfcode_node_modules_json3_README_autotoc_md14358}

\begin{DoxyItemize}
\item \href{http://nodejs.org/}{\texttt{ Node}} 0.\+6.\+21 and higher
\item \href{https://iojs.org/}{\texttt{ io.\+js}} 1.\+0.\+3 and higher
\item \href{http://ringojs.org/}{\texttt{ Ringo\+JS}} 0.\+9 and higher
\item \href{https://github.com/280north/narwhal}{\texttt{ Narwhal}} 0.\+3.\+2
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_json3_README_autotoc_md14359}{}\doxysubsection{Java\+Script Engines}\label{md_sfcode_node_modules_json3_README_autotoc_md14359}

\begin{DoxyItemize}
\item Mozilla \href{https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino}{\texttt{ Rhino}} 1.\+7\+R3 and higher
\item Web\+Kit \href{https://trac.webkit.org/wiki/JSC}{\texttt{ JSC}}
\item Google \href{http://code.google.com/p/v8/}{\texttt{ V8}}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_json3_README_autotoc_md14360}{}\doxysubsection{Known Incompatibilities}\label{md_sfcode_node_modules_json3_README_autotoc_md14360}

\begin{DoxyItemize}
\item Attempting to serialize the {\ttfamily arguments} object may produce inconsistent results across environments due to specification version differences. As a workaround, please convert the {\ttfamily arguments} object to an array first\+: {\ttfamily JSON.\+stringify(\mbox{[}\mbox{]}.slice.\+call(arguments, 0))}.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_json3_README_autotoc_md14361}{}\doxysubsection{Required Native Methods}\label{md_sfcode_node_modules_json3_README_autotoc_md14361}
JSON 3 assumes that the following methods exist and function as described in the ECMAScript specification\+:


\begin{DoxyItemize}
\item The {\ttfamily Number}, {\ttfamily String}, {\ttfamily Array}, {\ttfamily Object}, {\ttfamily Date}, {\ttfamily Syntax\+Error}, and {\ttfamily Type\+Error} constructors.
\item {\ttfamily String.\+from\+Char\+Code}
\item {\ttfamily Object\#to\+String}
\item {\ttfamily Object\#has\+Own\+Property}
\item {\ttfamily Function\#call}
\item {\ttfamily Math.\+floor}
\item {\ttfamily Number\#to\+String}
\item {\ttfamily Date\#value\+Of}
\item {\ttfamily String.\+prototype}\+: {\ttfamily index\+Of}, {\ttfamily char\+Code\+At}, {\ttfamily char\+At}, {\ttfamily slice}, {\ttfamily replace}.
\item {\ttfamily Array.\+prototype}\+: {\ttfamily push}, {\ttfamily pop}, {\ttfamily join}. 
\end{DoxyItemize}