Easily read/write JSON files in Deno
Reads a JSON file and then parses it into an object
import { readJson, readJsonSync } from 'https://deno.land/x/jsonfile/mod.ts';
const f = await readJson('./foo.json');
const foo = readJsonSync('./foo.json');
Writes an object to a JSON file.
You can also specify options from Deno.WriteFileOptions
to configure how the file is written.
import { writeJson, writeJsonSync } from 'https://deno.land/x/jsonfile/mod.ts';
writeJson('./target.json', { foo: 'bar' }, { spaces: 2 }); // returns a promise
writeJsonSync('./target.json', { foo: 'bar' }, { replacer: ['foo'] }); // void
// appends to the file instead of rewriting
writeJsonSync('./target.json', { foo: 'bar' }, { append: true });
Author: Maxvien
Demo: https://deno.land/x/jsonfile@1.0.0
Source Code: https://github.com/Maxvien/jsonfile
#deno #node #nodejs #javascript