how to write data to json file c** code example
Example 1: save json to file
import json
data = {}
with open('data.txt', 'w') as outfile:
json.dump(data, outfile)
Example 2: js writing to json file
var fs = require('fs');
var data = {}
data.table = []
for (i=0; i <26 ; i++){
var obj = {
id: i,
square: i * i
}
data.table.push(obj)
}
fs.writeFile ("input.json", JSON.stringify(data), function(err) {
if (err) throw err;
console.log('complete');
}
);