【问题标题】:JSON Jolt If ElseJSON 颠簸 If Else
【发布时间】:2022-12-11 18:12:18
【问题描述】:

有人可以帮我吗? 如果在“decision”中给出 01,我们从字段 A 以名称“First”显示,如果是 02,我们从字段 A 以名称“Second”显示。 在这两种情况下,我们都将“xyz”添加到末尾字段 A 中的值。

输入:

{
  "Some": {
    "Numbers": {
      "Number": [
        {
          "Int": {
            "A": "45618975618"
          }
        }
      ]
    },
    "Z": {
      "X": [
        {
          "decision": {
            "value": [
              "01"
            ]
          }
        }
      ]
    }
  }
}

01 的预期输出:

{
  "A" : {
    "B" : {
      "First" : {
        "A" : "45618975618XYZ"
      }
    }
  }
}

【问题讨论】:

    标签: json jolt


    【解决方案1】:

    您可以使用以下规范

    [
      {//conditionally match the respective values
        "operation": "shift",
        "spec": {
          "@(0,Some.Z.X[0].decision.value[0])": { // comparison criteria
            "01": {
              "@(2,Some.Numbers.Number[0].Int.A)": "A.B.First.A"
            },
            "02": { 
              "@(2,Some.Numbers.Number[0].Int.A)": "A.B.Second.A"
            }
          }
        }
      },
      {
       //add literal "XYZ" to the end of the returned value
        "operation": "modify-overwrite-beta",
        "spec": {
          "*": {
            "*": {
              "*": {
                "*": "=concat(@(1,&),'XYZ')"
              }
            }
          }
        }
      }
    ]
    

    演示在网站上 http://jolt-demo.appspot.com/

    【讨论】:

      猜你喜欢
      • 2022-08-05
      • 1970-01-01
      • 2019-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 2021-04-15
      • 1970-01-01
      相关资源
      最近更新 更多