英文:
Jolt Transform JSON Spec with Unknown keys
问题
[
{
"operation": "shift",
"spec": {
"*": {
"paramCollection": {
"*": {
"*": {
"@(1,&)": "[&3].&"
}
}
}
}
}
},
{
"operation": "default",
"spec": {
"*": {
"paramCollection": {
"*": {
"*": {
"limit": ""
}
}
}
}
}
}
]
英文:
I want to transform below input json to output json using JOLT. The main problem here is in the list, I have to remove some fields whose root key (Param1, Param2, ...) will differ dynamically. I tried below spec, which didn't work.
Need help in this case.
Input JSON : [
{
"paramCollection": [
{
"Param1": {
"value": 1,
"limit": "10"
}
},
{
"Param2": {
"value": 1,
"limit": "20"
}
}
]
}
]
Output JSON : [ {
"paramCollection" : [ {
"Param1" : {
"value" : 1
}
}, {
"Param2" : {
"value" : 1
}
} ]
} ]
spec : [
{
"operation": "remove",
"spec": {
"*": {
"paramCollection" : {
"*": {
"[&1].[&1].limit": ""
}
}
}
}
}
]
答案1
得分: 1
你几乎是正确的。这是稍微修改过的规范,应该可以工作:
[
{
"operation": "remove",
"spec": {
"*": {
"paramCollection": {
"*": {
"*": {
"limit": ""
}
}
}
}
}
}
]
[&1].[&1].
似乎是多余且不正确的。看起来 remove 操作 不支持 ampersand(&
)通配符。请参阅 shift 操作文档
&
通配符
- 适用于 LHS(左侧 - 输入 JSON 键)和 RHS(输出数据路径)
英文:
You are almost correct. This is the slightly modified spec which should work:
[
{
"operation": "remove",
"spec": {
"*": {
"paramCollection": {
"*": {
"*": {
"limit": ""
}
}
}
}
}
}
]
The [&1].[&1].
seems reduntant and incorrect. It seems that the remove operation does not support the apmersand (&
) wildcard. See the shift operation docs
>'&' Wildcard
> * Valid on the LHS (left hand side - input JSON keys) and RHS (output data path)
>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论