\begin{quote}
Parse JSON with more helpful errors \end{quote}
\hypertarget{md_sfcode_node_modules_parse_json_readme_autotoc_md20231}{}\doxysection{Install}\label{md_sfcode_node_modules_parse_json_readme_autotoc_md20231}

\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install parse-\/json }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_parse_json_readme_autotoc_md20232}{}\doxysection{Usage}\label{md_sfcode_node_modules_parse_json_readme_autotoc_md20232}

\begin{DoxyCode}{0}
\DoxyCodeLine{const parseJson = require('parse-\/json');}
\DoxyCodeLine{const json = '\{\(\backslash\)n\(\backslash\)t"{}foo"{}: true,\(\backslash\)n\}';}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{JSON.parse(json);}
\DoxyCodeLine{/*}
\DoxyCodeLine{undefined:3}
\DoxyCodeLine{\}}
\DoxyCodeLine{\string^}
\DoxyCodeLine{SyntaxError: Unexpected token \}}
\DoxyCodeLine{*/}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{parseJson(json);}
\DoxyCodeLine{/*}
\DoxyCodeLine{JSONError: Trailing comma in object at 3:1}
\DoxyCodeLine{\}}
\DoxyCodeLine{\string^}
\DoxyCodeLine{*/}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{parseJson(json, 'foo.json');}
\DoxyCodeLine{/*}
\DoxyCodeLine{JSONError: Trailing comma in object in foo.json:3:1}
\DoxyCodeLine{\}}
\DoxyCodeLine{\string^}
\DoxyCodeLine{*/}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{// You can also add the filename at a later point}
\DoxyCodeLine{try \{}
\DoxyCodeLine{    parseJson(json);}
\DoxyCodeLine{\} catch (err) \{}
\DoxyCodeLine{    err.fileName = 'foo.json';}
\DoxyCodeLine{    throw err;}
\DoxyCodeLine{\}}
\DoxyCodeLine{/*}
\DoxyCodeLine{JSONError: Trailing comma in object in foo.json:3:1}
\DoxyCodeLine{\}}
\DoxyCodeLine{\string^}
\DoxyCodeLine{*/ }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_parse_json_readme_autotoc_md20233}{}\doxysection{API}\label{md_sfcode_node_modules_parse_json_readme_autotoc_md20233}
\hypertarget{md_sfcode_node_modules_parse_json_readme_autotoc_md20234}{}\doxysubsection{parse\+Json(input, \mbox{[}reviver\mbox{]}, \mbox{[}filename\mbox{]})}\label{md_sfcode_node_modules_parse_json_readme_autotoc_md20234}
\hypertarget{md_sfcode_node_modules_parse_json_readme_autotoc_md20235}{}\doxysubsubsection{input}\label{md_sfcode_node_modules_parse_json_readme_autotoc_md20235}
Type\+: {\ttfamily string}\hypertarget{md_sfcode_node_modules_parse_json_readme_autotoc_md20236}{}\doxysubsubsection{reviver}\label{md_sfcode_node_modules_parse_json_readme_autotoc_md20236}
Type\+: {\ttfamily Function}

Prescribes how the value originally produced by parsing is transformed, before being returned. See \href{https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse\#Using_the_reviver_parameter}{\texttt{ {\ttfamily JSON.\+parse} docs}} for more.\hypertarget{md_sfcode_node_modules_parse_json_readme_autotoc_md20237}{}\doxysubsubsection{filename}\label{md_sfcode_node_modules_parse_json_readme_autotoc_md20237}
Type\+: {\ttfamily string}

Filename displayed in the error message.\hypertarget{md_sfcode_node_modules_parse_json_readme_autotoc_md20238}{}\doxysection{License}\label{md_sfcode_node_modules_parse_json_readme_autotoc_md20238}
MIT © \href{https://sindresorhus.com}{\texttt{ Sindre Sorhus}} 