-2

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?

Adam Kipnis
  • 10,175
  • 10
  • 35
  • 48
K Kolluru
  • 123
  • 4
  • 1
    Possible duplicate of [Parse JSON in JavaScript?](https://stackoverflow.com/questions/4935632/parse-json-in-javascript) – 31piy Apr 11 '18 at 14:26
  • It's parsing the JSON string into an object. What's confusing about it? – Herohtar Apr 11 '18 at 14:27

1 Answers1

-1

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"];
Anouar khaldi
  • 772
  • 6
  • 15