Reputation: 214
This is input JSON which has array, which can contain one or more objects. inside the object lang is array. It will always have one object which is fix. I want to flatten it.
[
{
"name": "James",
"id": 1,
"lang": [
{
"primary": "python",
"secondary": "c++"
}
]
},
{
"name": "Kevin",
"id": 2,
"lang": [
{
"primary": "scala",
"secondary": "java"
}
]
}
]
I want to flatten the JSON like this - expected output
[
{
"name": "James",
"id": 1,
"primary": "python",
"secondary": "c++"
},
{
"name": "Kevin",
"id": 2,
"primary": "scala",
"secondary": "java"
}
]
Im tryin to build specification like this but its not working
[
{
"operation": "shift",
"spec": {
"*": {
"name": "[&1].name",
"id": "[&1].id",
"lang": {
"*": {
"primary": "lang\\[&2\\]\\.primary",
"secondary": "lang\\[&2\\]\\.secondary"
}
}
}
}
}
]
Upvotes: 1
Views: 744
Reputation: 65105
[&2]
to [&3]
as the value on the right hand
side(in order to traverse the colon following the innermost "*"
)such as
[
{
"operation": "shift",
"spec": {
"*": {
"*": "[&1].&", // the rest of the attributes(other than "lang" array)
"lang": {
"*": {
"*": "[&3].&"
}
}
}
}
}
]
the demo on the site http://jolt-demo.appspot.com/ is
Upvotes: 1