appending to json file in javascript

后端 未结 2 1254
-上瘾入骨i
-上瘾入骨i 2020-12-19 02:29

I have a json file, employees.json, that I would like to append data to this object. The file looks like this:

var txt = \'{\"employees\":[\' +
\'{\"firstNam         


        
2条回答
  •  一整个雨季
    2020-12-19 03:23

    JSON stands for Javascript object notation so this could simply be a javascript object

    var obj = {employees:[
        {
          firstname:"jerry"
          ... and so on ...
         }
    ]};
    

    When you want to add an object you can simply do:

    object.employees.push({
       firstname: "Mike",
       lastName: "rut"
        ... and so on ....
    });
    

提交回复
热议问题