JSFiddle - React, Tailwind, and code Playground
HTML
Old:
<pre id="old"></pre>
<br />New:
<pre id="new"></pre>
JavaScript
var object = {
"items": {
"2": {
"id": 122,
"product_id": "DE",
"price": "9.35"
},
"4": {
"id": 15,
"product_id": "CH",
"price": "8.00"
},
"7": {
"id": 78,
"product_id": "CH",
"price": "3.00"
}
},
"total_price": "20.35",
"item_count": 2,
"unit": "CHF"
};
function format(object) {
var items = {};
var i = 0;
for (var index in object.items) {
items[i] = object.items[index];
i++;
}
object.items = items;
}
$('#old').html(JSON.stringify(object, null, 4));
// Change object
format(object);
$('#new').html(JSON.stringify(object, null, 4));