0

我有一个 JSON 输入,我正在使用 JOLT shift 进行转换。我的问题是我想使用输入键的值作为输出数据中的新键,并同时将另一个值添加到新的输出键中。这是我的输入:

"Description": {
  "Name": "John",
  "KeyNameId": "John123",
  "Description": "John's description"
}

我希望我的输出是:

"Description": {
  "John123": "John's description"
}

无论如何要在不使用两个班次操作的情况下做到这一点?或者如果一个不可能,则有两个班次?

4

2 回答 2

3

是的,可以使用“@(Number,words)”运算符在一个班次中完成。

输入 - 为清晰起见稍作修改

{
  "Top": {
    "Name": "John",
    "KeyNameId": "John123",
    "Description": "John's description"
  }
}

规格

[
  {
    "operation": "shift",
    "spec": {
      "Top": {
        // match the key "Description" and copy it's value to the Output.
        // The Output path being defined by @(1,KeyNameId), which means
        //  go back up the tree 2 levels (0,1) and lookup the value of 
        //  "KeyNameId"
        "Description": "@(1,KeyNameId)"
      }
    }
  }
]
于 2017-08-04T22:53:08.073 回答
0

更准确地说,

[
  {
    "operation": "shift",
    "spec": {
      "Description": {
        "@Description": "Description.@KeyNameId"
      }
    }
  }
]
于 2019-02-20T18:03:21.537 回答