Like JSON.\+stringify, but doesn\textquotesingle{}t throw on circular references.\hypertarget{md_sfcode_node_modules_json_stringify_safe_README_autotoc_md14309}{}\doxysection{Usage}\label{md_sfcode_node_modules_json_stringify_safe_README_autotoc_md14309}
Takes the same arguments as {\ttfamily JSON.\+stringify}.


\begin{DoxyCode}{0}
\DoxyCodeLine{var stringify = require('json-\/stringify-\/safe');}
\DoxyCodeLine{var circularObj = \{\};}
\DoxyCodeLine{circularObj.circularRef = circularObj;}
\DoxyCodeLine{circularObj.list = [ circularObj, circularObj ];}
\DoxyCodeLine{console.log(stringify(circularObj, null, 2)); }

\end{DoxyCode}


Output\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  "{}circularRef"{}: "{}[Circular]"{},}
\DoxyCodeLine{  "{}list"{}: [}
\DoxyCodeLine{    "{}[Circular]"{},}
\DoxyCodeLine{    "{}[Circular]"{}}
\DoxyCodeLine{  ]}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_json_stringify_safe_README_autotoc_md14310}{}\doxysection{Details}\label{md_sfcode_node_modules_json_stringify_safe_README_autotoc_md14310}

\begin{DoxyCode}{0}
\DoxyCodeLine{stringify(obj, serializer, indent, decycler) }

\end{DoxyCode}


The first three arguments are the same as to JSON.\+stringify. The last is an argument that\textquotesingle{}s only used when the object has been seen already.

The default {\ttfamily decycler} function returns the string `'\mbox{[}Circular\mbox{]}\textquotesingle{}{\ttfamily . If, for example, you pass in}function(k,v)\{\}{\ttfamily (return nothing) then it will prune cycles. If you pass in}function(k,v)\{ return \{foo\+: \textquotesingle{}bar\textquotesingle{}\}\}{\ttfamily , then cyclical objects will always be represented as}\{\char`\"{}foo\char`\"{}\+:\char`\"{}bar\char`\"{}\}\`{} in the result.


\begin{DoxyCode}{0}
\DoxyCodeLine{stringify.getSerialize(serializer, decycler) }

\end{DoxyCode}


Returns a serializer that can be used elsewhere. This is the actual function that\textquotesingle{}s passed to JSON.\+stringify.

{\bfseries{Note}} that the function returned from {\ttfamily get\+Serialize} is stateful for now, so do {\bfseries{not}} use it more than once. 