You are not logged in.

#1 2017-01-01 05:34:23


How to add data to an existing JSON file in the server side (with PHP)

Happy New Year David.

Please can you guide me on how to add more data to a JSON file using php.


In addition
I want to create a UI that the user will fill and send and get a success response  when the data is updated on a server.

Last edited by Tonym (2017-01-01 09:33:40)

#2 2017-01-01 11:19:18

From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,718

Re: How to add data to an existing JSON file in the server side (with PHP)

Hello Tonym,

In order to append JSON data or just play with JSON data (editing, adding, removing, etc.) using PHP there is only a way that I know and it's to decode the JSON file in order to get the saved structured data. Play with that data and, when finish, encode it as a JSON string and save to the file. All of these are based in the "json_decode" and "json_encode" PHP functions.

Said that remember that JSON can be very good to send and receive data from and to our applications, but we no need to store the data as is in the server side. In few words, we can save our application data in a server database, for example, and, maybe, send JSON data when the application requires someone, or use JSON to receive data from the application. But not necessarily store that data in a JSON file.

About the other question, that is, how to prepare an UI to send data to the application server, in fact there can't be more easy. You can take a look at several samples like the "HttpClient" one. We can show Inputs controls (several of them are included in App Builder like Text Input, Number Input, Date Input, etc., etc.) to the application user, and then just prepare the HttpClient to send the appropiate input's values to the application server.

Once the server receive our application HTTP call they can reply with the appropiate response, which is received by the application using the HttpClient control Error or (more commonly) Success event. Then we can do whatever we wanted with the server's response. And of course the server previously do whatever we wanted with the received application's data, like save it into a database, etc.

Happy New Year to you too Tonym! wink


Board footer

Powered by FluxBB