如何在JOLT转换中比较字段值?

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

我的输入如下,

输入:

{
  "a": 1,
  "b": 2
}

规格:

[
 {
  "operation": "shift",
  "spec": {
    "a": {
      "@(2,b)": {
        "#Matched": "result"
      },
      "*": {
        "#Not Matched": "result"
      }
    }
  }
}]

输出:

{
 "result" : [ "Matched", "Not Matched" ]
}

预期:

{
 "result" : "Not Matched" 
}

有人可以建议我帮我照常工作吗。

json transformation jolt
1个回答
0
投票

您可以通过三个步骤对其进行转换:

  1. 将值移动到键
  2. 查找匹配值
  3. 如果找不到匹配的值,则添加“不匹配”结果

类似:

[
  {
    "operation": "shift",
    "spec": {
      "*": "&.@0"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "a": {
        "*": {
          "@(2,b.&)": {
            "#Matched": "result"
          }
        }
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "result": "Not Matched"
    }
  }
]
© www.soinside.com 2019 - 2024. All rights reserved.