Insert data into an External Json

Asked

Viewed 977 times

6

How to insert data into an external Json file:

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

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

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

  • Herinque, as stated by zidnd, javascript cannot perform write/read operations on the client side, I advise you to use localstorage or sessionstorage to store data on the client side if this is really your intention

  • 1

    @Gabrielrodrigues ...is Zignd... and not zidnd... : P

  • @Zignd this! rsrs

  • I appreciate the answer, in my conception I understood that I could do this directly with javascript, I had forgotten that this was going to the server side, I appreciate the clarification.

1 answer

4


Javascript, when used by the browser, cannot perform write or read operations freely on the operating system file system.

What you could do is build a web application with some technology server-side, such as ASP.NET MVC or PHP for example, and through this application you perform write operations on that JSON file, also note that this file will 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 on a virtual file system, that is, you will have access to a directory that will only be of your application, within that directory you will be able to perform whatever operations you want, but you will not be able to exit from within it to access the operating system file system.

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

And to learn more about the File API recommend the articles below:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.