[英]Jolt transformation to add a attribute to a JSON object
I have two JSON objects as input and want to add a value of one object to the other.我有两个 JSON 对象作为输入,并希望将一个 object 的值添加到另一个。 I have tried many different specs, but I can't get it to work.我尝试了许多不同的规格,但我无法让它工作。
Here is an example of the situation:下面是一个例子:
Input:输入:
{
"all": {
"a": "1",
"b": "2",
"c": "3"
},
"partially": {
"d": "4",
"e": "5",
"f": "6"
}
}
I want to have all data from the "all" object and I do not know what keys will be present.我想从“所有”object 中获取所有数据,但我不知道会出现什么键。 On the other hand I know the keys of the "partially" object and I want to shift only selected.另一方面,我知道“部分” object 的键,我只想切换选中。 So for example here is a desired output:因此,例如这里是所需的 output:
{
"result" : {
"a" : "1",
"b" : "2",
"c" : "3",
"d" : "4"
}
}
This is my current spec, but it produces an array with separate data and does not select only "d" from the "partially".这是我当前的规范,但它会生成一个包含单独数据的数组,并且不会 select 仅来自“部分”的“d”。 If I try to select only "d" it shifts the value but not the key, but I need both:如果我尝试 select 仅“d”它会移动值而不是键,但我需要两者:
[
{
"operation": "shift",
"spec": {
"all": "result",
"partially": "result"
}
}
]
Is there any way to do this?有没有办法做到这一点? Thank you!谢谢!
Please try this spec,请试试这个规格,
[
{
"operation": "shift",
"spec": {
"all": {
"@": "result",
"@(1,partially.d)": "result.d"
}
}
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.