Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to modify external json file javascript

//All Other code has an error 
//Here is the correct one
fs = require('fs');
var name = 'fileName.json';
var m = JSON.parse(fs.readFileSync(name).toString());
for(const p in m){
    p.name= m.name;
}
fs.writeFileSync(name, JSON.stringify(m));
Comment

edit external json file in javascript

fs = require('fs');
var name = 'fileName.json';
var m = JSON.parse(fs.readFileSync(name).toString());
m.forEach(function(p){
    p.name= m.name;
});
fs.writeFileSync(name, JSON.stringify(m));
Comment

js read external json file js

fs = require('fs');
var name = 'myFile.json';
var m = JSON.parse(fs.readFileSync(name).toString());
m.forEach(function(p){
    p.name= m.name;
});
fs.writeFileSync(name, JSON.stringify(m));
Comment

PREVIOUS NEXT
Code Example
Javascript :: axios post request 
Javascript :: post request with data and headers 
Javascript :: html canvas not clearing 
Javascript :: react semantic button 
Javascript :: call multiple functions onclick react 
Javascript :: axios data fetch 
Javascript :: local vs global variables 
Javascript :: jquery datatable rest api 
Javascript :: create secure jwt secret key using node crypto 
Javascript :: innerhtml 
Javascript :: d3 not reading json 
Javascript :: data table is not a function in vue 
Javascript :: react time input 
Javascript :: reload parent window from prompt 
Javascript :: vue js use component everywhere 
Javascript :: reactjs cdn file 
Javascript :: javscript ajax request gmt header 
Javascript :: js fetch 
Javascript :: preventdefault javascript 
Javascript :: javascript date parse yyyy-mm-dd 
Javascript :: Javascript show password... 
Javascript :: react-native-community/blur 
Javascript :: vue displaying a this.length 
Javascript :: last item in array javascript 
Javascript :: javascript how to remove the last character of the string 
Javascript :: javascript deconstruct object 
Javascript :: how to insert with variables from js to mysql 
Javascript :: how to trigger image upload button in from another button react js 
Javascript :: array list in javascript 
Javascript :: react-floating-whatsapp 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =