Deterministic {\ttfamily JSON.\+stringify()} -\/ a faster version of \href{https://github.com/substack}{\texttt{ @substack}}\textquotesingle{}s json-\/stable-\/strigify without \href{https://github.com/substack/jsonify}{\texttt{ jsonify}}.

You can also pass in a custom comparison function.

\href{https://travis-ci.org/epoberezkin/fast-json-stable-stringify}{\texttt{ }} \href{https://coveralls.io/github/epoberezkin/fast-json-stable-stringify?branch=master}{\texttt{ }}\hypertarget{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10247}{}\doxysection{example}\label{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10247}

\begin{DoxyCode}{0}
\DoxyCodeLine{var stringify = require('fast-\/json-\/stable-\/stringify');}
\DoxyCodeLine{var obj = \{ c: 8, b: [\{z:6,y:5,x:4\},7], a: 3 \};}
\DoxyCodeLine{console.log(stringify(obj)); }

\end{DoxyCode}


output\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\{"{}a"{}:3,"{}b"{}:[\{"{}x"{}:4,"{}y"{}:5,"{}z"{}:6\},7],"{}c"{}:8\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10248}{}\doxysection{methods}\label{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10248}

\begin{DoxyCode}{0}
\DoxyCodeLine{var stringify = require('fast-\/json-\/stable-\/stringify') }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10249}{}\doxysubsection{var str = stringify(obj, opts)}\label{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10249}
Return a deterministic stringified string {\ttfamily str} from the object {\ttfamily obj}.\hypertarget{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10250}{}\doxysubsection{options}\label{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10250}
\hypertarget{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10251}{}\doxysubsubsection{cmp}\label{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10251}
If {\ttfamily opts} is given, you can supply an {\ttfamily opts.\+cmp} to have a custom comparison function for object keys. Your function {\ttfamily opts.\+cmp} is called with these parameters\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{opts.cmp(\{ key: akey, value: avalue \}, \{ key: bkey, value: bvalue \}) }

\end{DoxyCode}


For example, to sort on the object key names in reverse order you could write\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var stringify = require('fast-\/json-\/stable-\/stringify');}
\DoxyCodeLine{}
\DoxyCodeLine{var obj = \{ c: 8, b: [\{z:6,y:5,x:4\},7], a: 3 \};}
\DoxyCodeLine{var s = stringify(obj, function (a, b) \{}
\DoxyCodeLine{    return a.key < b.key ? 1 : -\/1;}
\DoxyCodeLine{\});}
\DoxyCodeLine{console.log(s); }

\end{DoxyCode}


which results in the output string\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\{"{}c"{}:8,"{}b"{}:[\{"{}z"{}:6,"{}y"{}:5,"{}x"{}:4\},7],"{}a"{}:3\} }

\end{DoxyCode}


Or if you wanted to sort on the object values in reverse order, you could write\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var stringify = require('fast-\/json-\/stable-\/stringify');}
\DoxyCodeLine{}
\DoxyCodeLine{var obj = \{ d: 6, c: 5, b: [\{z:3,y:2,x:1\},9], a: 10 \};}
\DoxyCodeLine{var s = stringify(obj, function (a, b) \{}
\DoxyCodeLine{    return a.value < b.value ? 1 : -\/1;}
\DoxyCodeLine{\});}
\DoxyCodeLine{console.log(s); }

\end{DoxyCode}


which outputs\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\{"{}d"{}:6,"{}c"{}:5,"{}b"{}:[\{"{}z"{}:3,"{}y"{}:2,"{}x"{}:1\},9],"{}a"{}:10\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10252}{}\doxysubsubsection{cycles}\label{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10252}
Pass {\ttfamily true} in {\ttfamily opts.\+cycles} to stringify circular property as {\ttfamily \+\_\+\+\_\+cycle\+\_\+\+\_\+} -\/ the result will not be a valid JSON string in this case.

Type\+Error will be thrown in case of circular object without this option.\hypertarget{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10253}{}\doxysection{install}\label{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10253}
With \href{https://npmjs.org}{\texttt{ npm}} do\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{npm install fast-\/json-\/stable-\/stringify }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10254}{}\doxysection{benchmark}\label{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10254}
To run benchmark (requires Node.\+js 6+)\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{node benchmark }

\end{DoxyCode}


Results\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{fast-\/json-\/stable-\/stringify x 17,189 ops/sec ±1.43\% (83 runs sampled)}
\DoxyCodeLine{json-\/stable-\/stringify x 13,634 ops/sec ±1.39\% (85 runs sampled)}
\DoxyCodeLine{fast-\/stable-\/stringify x 20,212 ops/sec ±1.20\% (84 runs sampled)}
\DoxyCodeLine{faster-\/stable-\/stringify x 15,549 ops/sec ±1.12\% (84 runs sampled)}
\DoxyCodeLine{The fastest is fast-\/stable-\/stringify }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10255}{}\doxysubsection{Enterprise support}\label{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10255}
fast-\/json-\/stable-\/stringify package is a part of \href{https://tidelift.com/subscription/pkg/npm-fast-json-stable-stringify?utm_source=npm-fast-json-stable-stringify&utm_medium=referral&utm_campaign=enterprise&utm_term=repo}{\texttt{ Tidelift enterprise subscription}} -\/ it provides a centralised commercial support to open-\/source software users, in addition to the support provided by software maintainers.\hypertarget{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10256}{}\doxysubsection{Security contact}\label{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10256}
To report a security vulnerability, please use the \href{https://tidelift.com/security}{\texttt{ Tidelift security contact}}. Tidelift will coordinate the fix and disclosure. Please do NOT report security vulnerability via Git\+Hub issues.\hypertarget{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10257}{}\doxysection{license}\label{md_sfcode_node_modules_fast_json_stable_stringify_README_autotoc_md10257}
\href{https://github.com/epoberezkin/fast-json-stable-stringify/blob/master/LICENSE}{\texttt{ MIT}} 