Insert data into an external Json

6

How do I insert data into an external Json file:

var json = 
{
  caminho: "img/minhaIMG.png",
  descricao: "minha descricão"
}

How can I insert new data into this json file? In my case, I would use the same as a "Database" of my files.

After creating the objJSON in my javascript, how can I insert it into my file?

    
asked by anonymous 22.11.2015 / 18:34

1 answer

4

JavaScript, when used by the browser, can not perform write or read operations freely on the operating system's file system.

What you could do is build a web application with some server-side technology, such as ASP.NET MVC or PHP for example, and through that application you perform write operations on that JSON file , note that this file will also be on the server side and not on the client side.

If you want to store and manipulate this JSON file on the client side you can use the File API that allows your application to interact with local files in a virtual file system, ie you will have access to a directory that will only be of your application, within that directory you will be able to perform any operations you wish, but you can not exit from it to access the operating system filesystem.

To learn more about the server-side technologies I mentioned above, I recommend you take a look at the wiki for the ASP.NET MVC and PHP tags:

And to learn more about the API File I recommend the following articles:

22.11.2015 / 18:44