-1

So i want to get a value from a json file, but for the life of it, i cant get to understand what to write.

So if someone could help me write this line of code in javascript node, i would be grateful. I am trying to get the value of "totalCount"

This is from a library called GeoDb just for context.

main.js(NODEjs)

const timezone = require("./TimezonePortugal.json"); //referencing the json

console.log(timezone.metadata); // i dont know what to say afther this

TimezonePortugal.json

{"data":[{"code":"EUR","countryCodes":["PT","YT","IE","AD","IT","AT","RE","AX","BE","BL","SI","SK","SM","CY","DE","LT","LU","LV","MC","ME","MF","EE","MQ","MT","VA","ES","NL","FI","FR","GF","GP","GR","PM"],"symbol":"€"}],"metadata":{"currentOffset":0,"totalCount":1}}

1 Answers1

0

"." means inside. If you want to get value of totalCount you have to think like this:

timezone.metadata.totalCount = totalCount inside the metada, metadata inside the timezone

For example:

var timezone=
{
      "data":[
               {
                  "code":"EUR",
                  "countryCodes": ["PT","YT",],
                  "symbol":"€"
                }
              ],
  "metadata": {
                "currentOffset":0,
                "totalCount":1
               }
}