Raj Nepali Raj Nepali - 4 months ago 9
JSON Question

how to remove only key from json object?

i have following json string.

{"Local People":{"label":"Local People","data":1},"Student":{"label":"Student","data":1}}

i want it to be formatted in following format

"label" : "Student",
"data" : 1
"label" : "Student",
"data" : 1

i have tried it many times but unable to change. please help.


After you have parsed the string with JSON.parse, you could take the keys of the object and iterate over the properties for a new array with the items.

var JSONstring='{ "Local People": { "label": "Local People", "data": 1 }, "Student": { "label": "Student", "data": 1 } }'
    object = JSON.parse(JSONstring),
    array = Object.keys(object).map(function(k) {
        return object[k];