I have done lots of research before I decided to post this question but I still can find a way of adding an element/data to a json file which is stored locally. I have managed to open and read it but not add data. Here is what I would like to happen:
before I run the script.
{"logins" : [
{
"name": "test",
"usernam": "t",
"passwor": "ber"
},
{
"name": "test2,
"usernam": "chi",
"passwor": "Chik"
}
]}
and then I really on a button click I would like to add a new element/data so It looks like:
{"logins" : [
{
"name": "test",
"usernam": "t",
"passwor": "ber"
},
{
"name": "test2",
"usernam": "chi",
"passwor": "Chik"
},
{
"name" : "test3"
"usernam" : "tester"
"passwor": "tester2"
]}
and all of this preferably should be done without node.js. I am running this through a script tag in my html
Many thanks.
I assume you have a local .JSON file you are trying to edit with plain JS.
And the answer is no. Without a server, that is practically impossible.
You can however change it client-side, but that'll just be for you, and would never save anywhere else.
This is all for security, because letting a web page change a file... Could also allow it to delete files, including system ones.
Use something simple like Node.js for a backend server that can handle this.
I'd also recommend hashing passwords.