There is data.json with such data:

 [ {"name":"checkbox_0","state":"false"}, {"name":"checkbox_3","state":"true"}, {"name":"checkbox_2","state":"true"} ] 

I get data using $.getJSON();

  1. How can I add a line like: {"name":"checkbox_5","state":"true"} ?

  2. How to write these changes back to data.json ?

  • Isn't it easier to send new data to the server and add it to a file there? - Deonis

1 answer 1

Push

 var data = [ {"name":"checkbox_0","state":"false"}, {"name":"checkbox_3","state":"true"}, {"name":"checkbox_2","state":"true"} ]; data.push({"name":"checkbox_5","state":"true"}); 
  • And how to write this updated structure back into data.json? - Richard B.
  • data.json lies on the server? We need a server method that will process the POST request and rewrite the file. - Sergey Mitrofanov
  • Yes, that is, js is no longer valid, only server language can do this? - Richard B.