Almost the same as \mbox{\hyperlink{md_sfcode_node_modules_fs_extra_docs_writeJson}{\`{}write\+Json\`{}}}, except that if the directory does not exist, it\textquotesingle{}s created.

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


\begin{DoxyItemize}
\item {\ttfamily file} {\ttfamily $<$String$>$}
\item {\ttfamily object} {\ttfamily $<$Object$>$}
\item {\ttfamily options} {\ttfamily $<$Object$>$}
\begin{DoxyItemize}
\item {\ttfamily spaces} {\ttfamily $<$Number$\vert$\+String$>$} Number of spaces to indent; or a string to use for indentation (i.\+e. pass `'\textbackslash{}t\textquotesingle{}{\ttfamily for tab indentation). See \mbox{[}the docs\mbox{]}(\href{https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify}{\texttt{ https\+://developer.\+mozilla.\+org/en-\/\+US/docs/\+Web/\+Java\+Script/\+Reference/\+Global\+\_\+\+Objects/\+JSON/stringify}}\#The\+\_\+space\+\_\+argument) for more info. -\/}EOL$<$\+String$>${\ttfamily Set EOL character. Default is}~\newline
{\ttfamily . -\/}replacer{\ttfamily \mbox{[}JSON replacer\mbox{]}(\href{https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify}{\texttt{ https\+://developer.\+mozilla.\+org/en-\/\+US/docs/\+Web/\+Java\+Script/\+Reference/\+Global\+\_\+\+Objects/\+JSON/stringify}}\#The\+\_\+replacer\+\_\+parameter)}
\item {\ttfamily Also accepts \mbox{[}}fs.\+write\+File$<$tt$>$options\mbox{]}(\href{https://nodejs.org/api/fs.html}{\texttt{ https\+://nodejs.\+org/api/fs.\+html}}\#fs\+\_\+fs\+\_\+writefile\+\_\+file\+\_\+data\+\_\+options\+\_\+callback) -\/callback$<$\+Function$>$\`{}
\end{DoxyItemize}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_fs_extra_docs_outputJson_autotoc_md11028}{}\doxysection{Example\+:}\label{md_sfcode_node_modules_fs_extra_docs_outputJson_autotoc_md11028}

\begin{DoxyCode}{0}
\DoxyCodeLine{const fs = require('fs-\/extra')}
\DoxyCodeLine{}
\DoxyCodeLine{const file = '/tmp/this/path/does/not/exist/file.json'}
\DoxyCodeLine{fs.outputJson(file, \{name: 'JP'\}, err => \{}
\DoxyCodeLine{  console.log(err) // => null}
\DoxyCodeLine{}
\DoxyCodeLine{  fs.readJson(file, (err, data) => \{}
\DoxyCodeLine{    if (err) return console.error(err)}
\DoxyCodeLine{    console.log(data.name) // => JP}
\DoxyCodeLine{  \})}
\DoxyCodeLine{\})}
\DoxyCodeLine{}
\DoxyCodeLine{// With Promises:}
\DoxyCodeLine{fs.outputJson(file, \{name: 'JP'\})}
\DoxyCodeLine{.then(() => fs.readJson(file))}
\DoxyCodeLine{.then(data => \{}
\DoxyCodeLine{  console.log(data.name) // => JP}
\DoxyCodeLine{\})}
\DoxyCodeLine{.catch(err => \{}
\DoxyCodeLine{  console.error(err)}
\DoxyCodeLine{\}) }

\end{DoxyCode}
 