Jolt 删除所有空值

Phi*_*ilG 2 specifications operation jolt

我想使用 Jolt 处理器实现 JSON 转换。我的 JSON 中有包含 null 的字段,我想删除所有这些字段...

{
  "myValue": 345,
  "colorValue": null,
  "degreeDayValue": null,
  "depthValue": null,
  "distanceValue": null
}
Run Code Online (Sandbox Code Playgroud)

...只是为了保留这个myValue领域。

我可以通过删除 Jolt 操作来实现这一点吗?

小智 9

要从内部数组中删除null值,请在代码末尾使用以下规范:

{
  "operation": "modify-overwrite-beta",
  "spec": {
    "*": "=recursivelySquashNulls"
  }
}
Run Code Online (Sandbox Code Playgroud)


Mil*_*o S 5

这是可能的,只是并不简单。需要两步。

规格::

[
  {
    "operation": "default",
    "spec": {
      // for all keys that have a null value
      //  replace that null value with a placeholder
      "*": "PANTS"
    }
  },
  {
    "operation": "shift",
    "spec": {
      // match all keys
      "*": {
        // if the value of say "colorValue" is PANTS
        //  then, match but do nothing.
        "PANTS": null,
        // otherwise, any other values are ok
        "*": {
          // "recreate" the key and the non-PANTS value
          // Write the value from 2 levels up the tree the "@1"
          //  to the key from 3 levels up the tree => "&2".
          "@1": "&2"
        }
      }
    }
  }
]
Run Code Online (Sandbox Code Playgroud)

生产:

{
  "myValue": 345
}
Run Code Online (Sandbox Code Playgroud)