I have original json like this. In general, my json is very large. To make things simpler and easier to understand I have reduced the entries.
{
"clientSettings":[
{
"clientId":12345,
"key":"abc",
"value":false
},
{
"clientId":12345,
"key":"def",
"value":false
},
{
"clientId":12345,
"key":"ghi",
"value":false
},
{
"clientId":9876,
"key":"lkmn",
"value":false
}
],
"productSettings":[
{
"productId":11,
"key":"jkl",
"value":true
},
{
"productId":11,
"key":"mno",
"value":true
},
{
"productId":12,
"key":"jkl",
"value":true
},
{
"productId":12,
"key":"mno",
"value":true
}
],
"customerSettings":[
{
"key":"enableData",
"value":false
},
{
"key":"minPriceValue",
"value":"1.0"
},
{
"key":"presentData",
"value":"AEGIS"
}
],
"thothTest":{
"9876":[
"K"
],
"5431":[
"A",
"L"
],
"5123":[
"L"
]
},
"osirisTest":{
"7678":[
"K"
]
}
}
- In `clientSettings` json array we have `clientId's` and their keys/values. For single `clientId`, I can have multiple different keys and values. For example - `12345` `clientId` has different keys and values as shown above.
- Similarly for `productSettings` as well.
- But for `customerSettings` I just have different keys and values.
- For `thothTest` and `osirisTest` I don't have to do anything.
I am thinking to redesign the above json so that I don't have to duplicate `clientId` and `productId` for each keys and values. As of now my json is huge because I have lot of `ids` which are same but with different keys and values.
So I came up with below new json design which can represent same above json -
{
"clientSettings":[
{
"clientId":12345,
"entries":[
{
"key":"abc",
"value":false
},
{
"key":"def",
"value":false
},
{
"key":"ghi",
"value":false
}
]
},
{
"clientId":9876,
"entries":[
{
"key":"lkmn",
"value":false
}
]
}
],
"productSettings":[
{
"productId":11,
"entries":[
{
"key":"jkl",
"value":true
},
{
"key":"mno",
"value":true
}
]
},
{
"productId":12,
"entries":[
{
"key":"jkl",
"value":true
},
{
"key":"mno",
"value":true
}
]
}
],
"customerSettings":[
{
"key":"enableData",
"value":false
},
{
"key":"minPriceValue",
"value":"10.28"
},
{
"key":"presentData",
"value":"AEGIS"
}
],
"thothTest":{
"9876":[
"K"
],
"5431":[
"A",
"L"
],
"5123":[
"L"
]
},
"osirisTest":{
"7678":[
"K"
]
}
}
**Problem Statement**
Now given an old json - Is there any way to convert it to new json format through some sort of script or linux commands? Since my json is very huge so doing it one by one for each id's gonna take some time so was thinking if we can convert my old json to new json through some linux commands then it can speed up the process.