Q:

Read and write json data in javascript with a chrome extention?

How can I read and write json data in javascript? I'm making a chrome extention that will read and write json and so far couldn't figure out how to do it.
I have a .json file in my chrome extention directory that I want to read and write data to
For example: If I had this code
    {
    "members": {
        "Thing": {
            "someValue": "1",
            "anotherValue": "2"
        }
    }
}

How could I read "someValue" from it?
or how could I make "anotherValue" equal to 3?
Any help is appreciated!

A:

You can use NodeJS 'fs' library for writing and reading files. 
Try if this works.

var fs = require('fs');
var x =   
{
    "members": {
        "Thing": {
            "someValue": "1",
            "anotherValue": "2"
        },
        "secondThing":{
            "secondValue":"3",
            "anotherSecondVal":"4"
        }
    }
}


fs.writeFile('members.json', JSON.stringify(x), 'utf8', (err,data)=>{
    //callback
});

fs.readFile('members.json','utf8',(err,data)=>{
    if(data){
        console.log(JSON.parse(data))
    } else{
        console.log(err)
    }
})

