Skip to content

How to read specific object from json file in JavaScript?

I’m trying to work with a json file but I can’t figure out how to read just a specific object from a json file.

My current code looks like this:

try {
    const data = fs.readFileSync("addresses.json", "utf8");
} catch (err) {

This works fine. However when I try to get some object from the file like this:


It doesn’t work because it is a string.

So my question is how can I read just a single object from the json file.

Thanks a lot!



const parsedData = JSON.parse(data)
const address = parsedData.address