JOLT 转换修改覆盖 - 替换数组中的元素值
我正在开发 JOLT 库来对 json 值进行更改。
对于键值项,我找到了一个解决方案,使用
"operation": "modify-overwrite-beta"
但是当涉及到编辑数组内的值时,我遇到了问题。
让我们以这个 JSON: SPEC 为例,
{
"parentModule": [
{
"childModule": {
"arrayModule": [
"KK",
"VV"
]
}
}
]
}
我正在使用
[
{
"operation": "modify-overwrite-beta",
"spec": {
"parentModule": {
"*": {
"childModule": {
"arrayModule": [
"TT",
"RR"
]
}
}
}
}
}
]
我想要的结果是该数组完全被覆盖,但目前它仅替换第一个值。
预期结果:
{
"parentModule": [
{
"childModule": {
"arrayModule": [
"TT",
"RR"
]
}
}
]
}
有没有办法:
- 完全覆盖数组?
- 有条件地更改值,例如如果 TT =>更改为 AB,否则如果 RR 则写成 BB ?
谢谢
I am working on JOLT library to perform a change to the json values.
For key-value items I found a solution using
"operation": "modify-overwrite-beta"
But when it comes to edit values inside the arrays I encounter problems.
Let's have for example this JSON:
{
"parentModule": [
{
"childModule": {
"arrayModule": [
"KK",
"VV"
]
}
}
]
}
SPEC I am using
[
{
"operation": "modify-overwrite-beta",
"spec": {
"parentModule": {
"*": {
"childModule": {
"arrayModule": [
"TT",
"RR"
]
}
}
}
}
}
]
The result I want is that the array is totally override , but currently it is replacing only the first value.
Result expected:
{
"parentModule": [
{
"childModule": {
"arrayModule": [
"TT",
"RR"
]
}
}
]
}
Is there any way to:
- completely override the array?
- change values conditionally, for example if TT => change to AB, else if RR than write BB ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 shift 转换与
#
运算符一起使用,以表示要创建的新列表的固定元素值。对于第一种情况(如果我们有
"arrayModule": ["KK", "VV"]
输入 ) :demo1 :
第二次(如果我们有
"arrayModule": ["TT", "RR"]
作为输入 ) :demo2 :
同时设置适当的与号级别以分别在多个级别达到所需的键名称。
You can use shift transformations along with
#
operators in order to represent the fixed element values for the new lists to be created.For the first case( if we have
"arrayModule": ["KK", "VV"]
for the input ) :the demo1 :
And for the second ( if we have
"arrayModule": ["TT", "RR"]
for the input ) :the demo2 :
while setting proper ampersand levels to reach the desired key names at several levels respectively.