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\#readfilefilename-options-callback}{\texttt{ {\ttfamily json\+File.\+read\+File}}}.

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


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

\begin{DoxyCode}{0}
\DoxyCodeLine{const fs = require('fs-\/extra')}
\DoxyCodeLine{}
\DoxyCodeLine{fs.readJson('./package.json', (err, packageObj) => \{}
\DoxyCodeLine{  if (err) console.error(err)}
\DoxyCodeLine{}
\DoxyCodeLine{  console.log(packageObj.version) // => 0.1.3}
\DoxyCodeLine{\})}
\DoxyCodeLine{}
\DoxyCodeLine{// Promise Usage}
\DoxyCodeLine{fs.readJson('./package.json')}
\DoxyCodeLine{.then(packageObj => \{}
\DoxyCodeLine{  console.log(packageObj.version) // => 0.1.3}
\DoxyCodeLine{\})}
\DoxyCodeLine{.catch(err => \{}
\DoxyCodeLine{  console.error(err)}
\DoxyCodeLine{\}) }

\end{DoxyCode}


\DoxyHorRuler{0}


{\ttfamily read\+Json()} 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{fs.readJson(file, \{ throws: false \}, (err, obj) => \{}
\DoxyCodeLine{  if (err) console.error(err)}
\DoxyCodeLine{}
\DoxyCodeLine{  console.log(obj) // => null}
\DoxyCodeLine{\})}
\DoxyCodeLine{}
\DoxyCodeLine{// Promise Usage}
\DoxyCodeLine{fs.readJson(file, \{ throws: false \})}
\DoxyCodeLine{.then(obj => \{}
\DoxyCodeLine{  console.log(obj) // => null}
\DoxyCodeLine{\})}
\DoxyCodeLine{.catch(err => \{}
\DoxyCodeLine{  console.error(err) // Not called}
\DoxyCodeLine{\}) }

\end{DoxyCode}
 