Skip to Content
0

I want to create new file and append the data whenever new user register in my application.

Aug 29, 2017 at 02:33 PM

49

avatar image
Former Member

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?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Sharath M G Aug 30, 2017 at 02:24 AM
0

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 
}}); 
Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thanks for your response. Sorry that I am responding very much late.

Actually I am using trial account, and could not able to connect to database. But now I have got the way by calling web services built by me in PHP and MySQL.

0
Jun Wu Aug 29, 2017 at 03:18 PM
0

no way.

Share
10 |10000 characters needed characters left characters exceeded