Reads a JSON file and then parses it into an object. {\ttfamily options} are the same that you\textquotesingle{}d pass to \href{https://github.com/jprichardson/node-jsonfile\#readfilesyncfilename-options}{\texttt{ {\ttfamily json\+File.\+read\+File\+Sync}}}.

{\bfseries{Alias\+:}} {\ttfamily read\+JSONSync()}


\begin{DoxyItemize}
\item {\ttfamily file} {\ttfamily $<$String$>$}
\item {\ttfamily options} {\ttfamily $<$Object$>$}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_fs_extra_docs_readJson_sync_autotoc_md11033}{}\doxysection{Example\+:}\label{md_sfcode_node_modules_fs_extra_docs_readJson_sync_autotoc_md11033}

\begin{DoxyCode}{0}
\DoxyCodeLine{const fs = require('fs-\/extra')}
\DoxyCodeLine{}
\DoxyCodeLine{const packageObj = fs.readJsonSync('./package.json')}
\DoxyCodeLine{console.log(packageObj.version) // => 2.0.0 }

\end{DoxyCode}


\DoxyHorRuler{0}


{\ttfamily read\+Json\+Sync()} can take a {\ttfamily throws} option set to {\ttfamily false} and it won\textquotesingle{}t throw if the JSON is invalid. Example\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const fs = require('fs-\/extra')}
\DoxyCodeLine{}
\DoxyCodeLine{const file = '/tmp/some-\/invalid.json'}
\DoxyCodeLine{const data = '\{not valid JSON'}
\DoxyCodeLine{fs.writeFileSync(file, data)}
\DoxyCodeLine{}
\DoxyCodeLine{const obj = fs.readJsonSync(file, \{ throws: false \})}
\DoxyCodeLine{console.log(obj) // => null }

\end{DoxyCode}
 