I have a JSONObject inside a JSONArray (like the below JSON). Now I have to add the productID value as the KEY of the Object like the Required JSON. I'm trying to do this via javascript. But I can't get the desired output.
I tried to find any solution on Google. But it doesn't work out. Can anyone guide me how to do this or show me any references ?
ORIGINAL JSON
[
{
"productID": "C05M01P001",
"productName": "Aashirvaad Atta - Whole Wheat (முழு கோதுமை)",
"productUnit": "1 kg",
"productPrice": "Rs.50.00",
"productSellingPrice": "",
"productSID": "",
"productImage": "http://www.thechert.com/image/cache/Product_Images_2016/asvd-attaplain-atta-large-500x500.jpg",
"productDescription": "Ashirvaad Atta - Whole Wheat 1 kg..",
"productCID": "C05",
"productMID": "M01"
},
..... it goes on
]
Required JSON
{
"C05M01P001" : {
"productID": "C05M01P001",
"productName": "Aashirvaad Atta - Whole ",
"productUnit": "1 kg",
"productPrice": "Rs.50.00",
"productSellingPrice": "",
"productSID": "",
"productImage": "http://www.thechenart.com/image/cache/Product_Images_2016/asvd-attaplain-atta-large-500x500.jpg",
"productDescription": "Ashirvaad Atta - Whole Wheat 1 kg",
"productCID": "C05",
"productMID": "M01"
},
..... it goes on
}
required JSONcan be a object, not an array.[ { "C05M01P001: {...}}, {"C05M01P002": {...}} ]or (probably makes more sense) a single object{"C05M01P001: {...}, "C05M01P002": {...}}- which do you need?