I have an input json which is read from a denormalized table. In my scala application, I need to normalize it before returning the resultset.
If below is the sample input:
inputJson = {
"k1": "v0",
"k2": [{
"k21": [
"v1",
"v2",
"v3"
]}, {
"k22": [
"v2",
"v3",
"v4"
]
}]
}
my output json should look as follows:
outputJson = {
"k1": "v0",
"k2": [{
"k21": [1, 2, 3]
}, {
"k22": [2, 3, 4]
}],
"values": [{
"1": "v1"
}, {
"2": "v2"
}, {
"3": "v3"
}, {
"4": "v4"
}]
}
How can I achieve this in scala elegantly with/without using any json manipulation libraries