Deno.js Tutorial to Read and Write JSON Objects to Files Using TypeScript Full Project For Beginners




Easily read/write JSON files in Deno


Reads a JSON file and then parses it into an object

import { readJson, readJsonSync } from '';

const f = await readJson('./foo.json');
const foo = readJsonSync('./foo.json');


Writes an object to a JSON file.


  • replacer : An array of strings and numbers that acts as a approved list for selecting the object properties that will be stringified.
  • space : Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.

You can also specify options from Deno.WriteFileOptions to configure how the file is written.

import { writeJson, writeJsonSync } from '';

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 });


See also  Deno.js Tutorial to Capture Webpage Screenshot as PNG Image in Headless Mode Using deno-shot Library in TypeScript Full Project For Beginners





Leave a Reply