I am currently working on parsing a JSON object to extract the key and value combined into a variable. The desired output I want from the provided JSON is:
"/" - 7.84 GiB; "/opt" - 4.86 GiB; "/usr" - 4.80 GiB
While I can retrieve objects using my code snippet, I am facing difficulties in formatting the name and value as required. Any assistance would be greatly appreciated.
for (i = 0; i < obj.length; i++)
{
if ( obj[i].name === 'mountpoints')
{
js_mountpoints = obj[i].value;
break;
}
js_mountpoints = 'NA';
}
This is the JSON input that I am working with:
[{
"name" : "pe_build",
"value" : "2016.2.1"
},
{
"name" : "kernel",
"value" : "Linux"
}, {
"name" : "blockdevices",
"value" : "sda,sdb,sr0"
},
{
"name" : "mountpoints",
"value" : {
"\/boot\/efi" : {
"size_bytes" : 261861376,
"size" : "249.73 MiB",
"capacity" : "0%"
},
"\/opt" : {
"size_bytes" : 2086666240,
"size" : "1.94 GiB",
"capacity" : "1.64%"
},
"\/boot" : {
"size_bytes" : 258650112,
"size" : "246.67 MiB",
"capacity" : "74.28%"
},
"\/var" : {
"size_bytes" : 10475274240,
"size" : "9.76 GiB",
"filesystem" : "xfs",
"capacity" : "4.01%"
}
}
}, {
"name" : "uptime_seconds",
"value" : 244181
}, {
"name" : "memoryfree",
"value" : "6.66 GiB"
}, {
"name" : "memoryfree_mb",
"value" : 6816.91796875
}
]