on 08-29-2017 3:33 PM
I am using SAUI5 in SAP WEB IDE and want to create new JSON file and append the data whenever new user register in my application. I am able to read the JSON file but need to write the data and file. Can any one help me for the same?
Why are you trying to add it to file instead of creating it in a JSON object? If it's to store it permanently, it's not the best option.
Still, if you need to, then you can always get the file and then manually push content by structuring it.
Check this snippet relevant to you:
fs.readFile('myjsonfile.json', 'utf8', function readFileCallback(err, data){
if (err){
console.log(err);
} else {
obj = JSON.parse(data); //now it an object
obj.table.push({id: 2, square:3}); //add some data
json = JSON.stringify(obj); //convert it back to json
fs.writeFile('myjsonfile.json', json, 'utf8', callback); // write it back
}});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
no way.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.