在 Jolt 变换中展平 JSON 数组
Flatten JSON array in Jolt Transform
输入:
[
{
"name": "Foo",
"ratings": [
{
"value": 2
},
{
"value": 4
}
]
}
]
规格:
[
{
"operation": "shift",
"spec": {
"*": {
"ratings": {
"@": ""
}
}
}
}
]
输出:
[ {
"value" : 2
}, {
"value" : 4
} ]
我想达到的目标:
[ {
"name": "Foo",
"value" : 2
}, {
"name": "Foo",
"value" : 4
} ]
关于如何修改我的颠簸规范以实现该输出有什么想法吗?
[
{
"operation": "shift",
"spec": {
"*": { // top level array
"ratings": {
"*": { // ratings array
// push name down, but maintain the
// same doubly nested array structure
"@(2,name)": "[&3].[&1].name",
// copy everything inside a ratings document
"*": "[&3].[&1].&"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": { // top level array
// 2nd level array
"*": "[]"
}
}
}
]
输入:
[
{
"name": "Foo",
"ratings": [
{
"value": 2
},
{
"value": 4
}
]
}
]
规格:
[
{
"operation": "shift",
"spec": {
"*": {
"ratings": {
"@": ""
}
}
}
}
]
输出:
[ {
"value" : 2
}, {
"value" : 4
} ]
我想达到的目标:
[ {
"name": "Foo",
"value" : 2
}, {
"name": "Foo",
"value" : 4
} ]
关于如何修改我的颠簸规范以实现该输出有什么想法吗?
[
{
"operation": "shift",
"spec": {
"*": { // top level array
"ratings": {
"*": { // ratings array
// push name down, but maintain the
// same doubly nested array structure
"@(2,name)": "[&3].[&1].name",
// copy everything inside a ratings document
"*": "[&3].[&1].&"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": { // top level array
// 2nd level array
"*": "[]"
}
}
}
]