var data = '{ "1": "a", "2": "b", "3": "c"}';
var parsedData = JSON.parse(data);
var arr = [];
for(item in parsedData) {
arr.push({
"id": parseInt(item),
"value": parsedData[item]
});
};
console.log(arr);
Here we can create a random JSON object, and if you notice, the last value doesn't have a trailing comma. In JSON, you cannot have a trailing comma or else you will get an error. You also do not have to put numbers in double quotes in JSON. I'm not sure if that's just how your data is formatted, but you don't need to do that. After you get rid of the trailing comma, you should be able to call JSON.parse() and store the data in a JavaScript object. After that we can iterate through the valid object and push the values to the array. Since you have double quotes around the numbers in your JSON object I parsed them to integers sense that's what you look like you are trying to achieve in your final output. I'd also highlight that your data is not JSON, but it simply looks like a JSON object. We don't know if you're getting this data from a JSON file, or if you're adding it manually, but if you are adding it manually, you will need to make it a valid JSON string like I have above.