Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- * Write and Read JSON object to and from a file using NODE.JS
- */
- var fs = require("fs");
- // get data from file
- const data = require('./object.json');
- var sampleObject = [
- {
- name: 'Sobhit Kumar',
- job: 'Full Stack Developer',
- experience: '1.4 years'
- },
- {
- name: 'Vicky Kumar',
- job: 'Full Stack Developer',
- experience: '3.5 years'
- },
- ];
- // Write data to a file
- fs.writeFile("./object.json", JSON.stringify(sampleObject, null, 4), (err) => {
- if (err) { console.error(err); return; };
- console.log("File has been created");
- // read data from file
- console.log(data);
- });
- /***
- * Write and Read JSON object to and from a file in Angular
- */
- // Write data to json file
- npm install file-saver
- import { saveAs } from 'file-saver';
- var sampleObject = [
- {
- name: 'Sobhit Kumar',
- job: 'Full Stack Developer',
- experience: '1.4 years'
- },
- {
- name: 'Vicky Kumar',
- job: 'Full Stack Developer',
- experience: '3.5 years'
- },
- ];
- const blob = new Blob([JSON.stringify(sampleObject)], {type : 'application/json'});
- saveAs(blob, 'contractData.json');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement