I have this index.js and it's logging the whole .json file. I want to log the age (21). How do I do that?
const fs = require('fs');
async function doSomething() {
const data = fs.readFileSync("./apple.json")
const data2 = await JSON.parse(data)
console.log(JSON.stringify(data2, null, 2))
}
doSomething()
and a side question: Is there a way to avoid using fs to read files?
/*
apple.json
{
"memberList":[
{
"age":"21",
"name":"Jom"
}
]
}
*/
/*
Output:
{
"memberList": [
{
"age": "21",
"name": "Jom"
}
]
}
*/