I have an json data like this
[
{
"Name": "User1",
"primaryRegion": "US"
},
{
"Name": "user2",
"primaryRegion": "US"
},
{
"Name": "user3",
"primaryRegion": "US"
},
{
"Name": "user4",
"primaryRegion": "US"
},
{
"Name": "user5",
"primaryRegion": "US"
}
]
I just want to get the unique value of keys (Json Headers) in an array like this:
["Name", "primaryRegion"]
I tried below code but not getting expected result:
let jsonData = JSON.parse(fs.readFileSync('./test/sampleData1.json', 'utf8'));
console.log("JSON Fields---", Object.keys(jsonData));
It gives below output:
JSON Fields--- [
'0', '1', '2',
'3', '4'
]