Skip to Content
avatar image
Former Member

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

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?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Aug 30, 2017 at 02:24 AM

    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 
    }}); 
    
    Add comment
    10|10000 characters needed 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.

  • Aug 29, 2017 at 03:18 PM

    no way.

    Add comment
    10|10000 characters needed characters exceeded