英文:
How to unlist JSON item with lists into multiple items using JOLT?
问题
以下是翻译好的部分:
[
{
"cume": 150,
"region": "North",
"type": "total"
},
{
"cume": 200,
"region": "North",
"type": "app"
},
{
"cume": 300,
"region": "North",
"type": "web"
},
{
"cume": 360,
"region": "North",
"type": "registered"
},
{
"cume": 1000,
"region": "South",
"type": "total"
},
{
"cume": 1200,
"region": "South",
"type": "app"
},
{
"cume": 3500,
"region": "South",
"type": "web"
},
{
"cume": 6200,
"region": "South",
"type": "registered"
}
]
不包括代码部分的翻译已提供。
英文:
I have the input raw JSON file like this below:
[
{
"itemId": "001",
"region": "North",
"cume": [
150,
200,
300,
360
],
"type": [
"total",
"app",
"web",
"registered"
]
},
{
"itemId": "002",
"region": "South",
"cume": [
1000,
1200,
3500,
6200
],
"type": [
"total",
"app",
"web",
"registered"
]
}
]
And my expected output is:
[
{
"cume": 150,
"region": "North",
"type": "total"
},
{
"cume": 200,
"region": "North",
"type": "app"
},
{
"cume": 300,
"region": "North",
"type": "web"
},
{
"cume": 360,
"region": "North",
"type": "registered"
},
{
"cume": 1000,
"region": "South",
"type": "total"
},
{
"cume": 1200,
"region": "South",
"type": "app"
},
{
"cume": 3500,
"region": "South",
"type": "web"
},
{
"cume": 6200,
"region": "South",
"type": "registered"
}
]
What I have tried is below (it's not working)
[
{
"operation": "shift",
"spec": {
"*": {
"*s": {
"*": {
"@": "[&1].&(2,1)",
"@(2,region)": "[&1].region"
}
}
}
}
}
]
My current output converts everything into a single list. For example, for the region field, the output has four items inside instead of a single item.
答案1
得分: 1
这是您的 jolt 规范:
[
{
"operation": "shift",
"spec": {
"*": {
"cume": {
"*": {
"@": "[&3][&1].&2",
"@(2,region)": "[&3][&1].region",
"@(2,type[&])": "[&3][&1].type"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": ""
}
}
}
]
英文:
This is your jolt spec:
[
{
"operation": "shift",
"spec": {
"*": {
"cume": {
"*": {
"@": "[&3][&1].&2",
"@(2,region)": "[&3][&1].region",
"@(2,type[&])": "[&3][&1].type"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": ""
}
}
}
]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论