** Scenario:**
- I am using lodash to remove the empty key from my JSON.
But when it removes the keys it converts my array in an object for example
{ "projection": "Miller", "series": [ { "mapPolygons": { "states": { "hover": { "properties": { "fill": "#67b7dc" } } } }, "heatRules": { "0": { "min": "#a82626", "max": "#AAAA00" } }, "data": { "0": { "id": "US", "value": 3461.37 }, "1": { "id": "DE", "value": 2858.09 }, "2": { "id": "NO", "value": 3418.87 }, "3": { "id": "ES", "value": 3522.46 } } } ], "zoomControl": { "slider": { "height": 100 } }, "titles": { "0": { "fontSize": 20 } }, "homeZoomLevel": 1 }
Problem:
If you see in the above code there is heatRules property which is an array after converting it is converted into object of 0, again if you see data attribute it does same if you see titles attribute it does same over there.
i have used below link code to remove empty object and null object:
Why lodash converts my array into object?
Input Data:
{
"projection": "Miller",
"series": [
{
"mapPolygons": {
"states": {
"hover": {
"properties": {
"fill": "#67b7dc",
"size": ""
}
}
}
},
"heatRules": [
{
"min": "#a82626",
"max": "#AAAA00",
"fill": null
}
],
"data": [
{
"id": "US",
"value": 3461.37
},
{
"id": "DE",
"value": 2858.09
},
{
"id": "NO",
"value": 3418.87
},
{
"id": "ES",
"value": 3522.46
}
]
}
],
"zoomControl": {
"slider": {
"height": 100
}
},
"titles": [
{
"fontSize": 20,
"fontColor": ""
}
],
"homeZoomLevel": 1
}
Output Data:
{
"projection": "Miller",
"series": [
{
"mapPolygons": {
"states": {
"hover": {
"properties": {
"fill": "#67b7dc"
}
}
}
},
"heatRules": [
{
"min": "#a82626",
"max": "#AAAA00"
}
],
"data": [
{
"id": "US",
"value": 3461.37
},
{
"id": "DE",
"value": 2858.09
},
{
"id": "NO",
"value": 3418.87
},
{
"id": "ES",
"value": 3522.46
}
]
}
],
"zoomControl": {
"slider": {
"height": 100
}
},
"titles": [
{
"fontSize": 20
}
],
"homeZoomLevel": 1
}
If you see above output it removes null and blank key from properties -> size, heatRulues -> fill and from title it removes fontColor.