I am looking at javascript file on this page. It has a piece of code.
let source = fs.readFileSync("contracts.json");
let contracts = JSON.parse(source)["contracts"];
what does the JSON.parse function does exactly here?
I am looking at javascript file on this page. It has a piece of code.
let source = fs.readFileSync("contracts.json");
let contracts = JSON.parse(source)["contracts"];
what does the JSON.parse function does exactly here?
in this case the JSON.parse
It convert the source
file (contracts.json) to json object and JSON.parse("contracts.json")["contracts"]
It gives you the key contracts value.
You can type the code as follows :
let json_obj= JSON.parse(source);
let contracts = json_obj["contracts"];