Jolt Transformation - 替换所有火柴

问题描述 投票:0回答:1

我正在尝试使用以下方法使JOLT转换正常工作 https:/jolt-demo.appspot.com。.

我想把所有的 "master "值替换为 "7.11"。

输入:"7.11"。

{
  "build": [
    {
      "number": "7.11.13898",
      "branchName": "branch1"
    },
    {
      "number": "7.11.13896",
      "branchName": "branch2"
    },
    {
      "number": "7.11.13895",
      "branchName": "master"
    },
    {
      "number": "7.11.13900",
      "branchName": "master"
    }
  ]
}

希望的输出。

{
      "build": [
        {
          "number": "7.11.13898",
          "branchName": "branch1"
        },
        {
          "number": "7.11.13896",
          "branchName": "branch2"
        },
        {
          "number": "7.11.13895",
          "branchName": "7.11"
        },
        {
          "number": "7.11.13900",
          "branchName": "7.11"
        }
      ]
    }

我似乎无法在不改变数据结构的情况下进行转换或移动 目前的方法:

[
  {
    "operation": "shift",
    "spec": {
      "build": {
        "*": {
          "number": "build[&1].number",
          "branchName": {
            "master": {
              "#7.11": "build[&3].branchName"
            },
            "*": {
              "@(2, branchName)": "build[&3].branchName"
            }
          }
        }
      }
    }
  }
]

目前的方法:

 {
  "build" : [ {
    "number" : "7.11.13898"
  }, {
    "number" : "7.11.13896"
  }, {
    "branchName" : "7.11",
    "number" : "7.11.13895"
  } ]
}
json transformation jolt
1个回答
1
投票

你几乎找到了。你需要替换 @(2, branchName)$ 它应该对你有用。

"$"操作符的意思是使用输入键,而不是输入值作为输出。

解决办法。

[
  {
    "operation": "shift",
    "spec": {
      "build": {
        "*": {
          "number": "build[&1].number",
          "branchName": {
            "master": {
              "#7.11": "build[&3].branchName"
            },
            "*": {
              "$": "build[&3].branchName"
            }
          }
        }
      }
    }
  }
]
© www.soinside.com 2019 - 2024. All rights reserved.