使用 Jolt 对多种类型的字段值进行条件检查以清除/清空字段

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

我有以下 JSON

[
  {
    "field1": "xyz",
    "field2": "mno",
    "res1": "pqrs"
  },
  {
    "field1": "xyz1",
    "field2": "mno1",
    "res1": "pqrs1"
    
  }..other entries
]

下面的 jolt 规范可以很好地清空该字段,但我需要在清空

/folder1/subfolder/name
 之前检查 field1 的值是否为 
/folder2/subfolder/name
/folder3/subfolder/name
res1

[
  {
    "operation": "default",
    "spec": {
      "*": {
        "*": {
          "res": ""
        }
      }
    }
  }
]

需要帮助更新上述内容以进行 Jolt Spec 中的条件检查

已编辑——我需要喜欢这个(这不起作用)

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "if": "field1 == '/abc/bvcd' || field1 == '/xyz/prq/'",
        "then": {
          "res1": ""
        },
        "else": {}
      }
    }
  }
]
json conditional-statements jolt
1个回答
0
投票

您可以使用以下规格:

[
  { //separate the objects by indexes and "field1" values
    //considering the case of "field1" values to be identical 
    //for different objects
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&1.@1,field1.&"
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "/folder1/subfolder/name?|/folder2/subfolder/name?|/folder3/subfolder/name?": {
          "res1": ""
        }
      }
    }
  },
  { //get rid of the outer keys
    "operation": "shift",
    "spec": {
      "*": {
        "*": "[]"
      }
    }
  }
]
© www.soinside.com 2019 - 2024. All rights reserved.