在 Jolt 中组合列表时进行空检查

Null check while combining the list in Jolt

正在从第一个数组元素和第二个元素中提取值并将两者连接起来。输入字符串:

需要 Null 或 Empty 检查。

[
  {
    "creationDate": "2020-04-01T14:14:32.685+0000",
    "factValues": [
      {
        "Factname": "Medicine",
        "factvalue": "1234556",
        "sourcePguid": "1"
      },
      {
        "Factname": "Journal",
        "factvalue": "123455",
        "sourcePguid": null
      }
    ]
  },
  {
    "creationDate": "2020-04-01T14:14:32.685+0000",
    "factValues": [
      {
        "Factname": "chemical",
        "factvalue": "123455567",
        "sourcePguid": "2"
      },
      {
        "Factname": "Rubber",
        "factvalue": "123455435",
        "sourcePguid": "3"
      }
    ]
  }
]

输出除外:

  {
       {
        "sourcePguid" : "1",
        "Medicine":"1234556"

      }, {
        "sourcePguid" : "2",
        "chemical":"123455567",
        "Rubber":"123455435"
      } 
    }

请帮助我在 spec.json 中实现预期的 output.json。规范未按预期输出进行转换。我想学习如何使用字符串中的属性 parser.It 会很棒。

这可能有帮助,

[
  {
    //Removes the fields having null from the JSON
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=recursivelySquashNulls"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            //Shift only if sourcePguid is present
            "sourcePguid": {
              "@": "&4.sourcePguid",
              "@(1,factvalue)": "&4.@(2,Factname)"
            }
          }
        }
      }
    }
  },
  {
    // Select the first element from sourcePguid array shifted
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "sourcePguid": "=firstElement(@(1,sourcePguid))"
      }
    }
}
]