【问题标题】:Jolt remove all null values颠簸删除所有空值
【发布时间】:2018-03-22 06:49:09
【问题描述】:

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

{...............
            "myValue": 345,
            "colorValue": null,             
            "degreeDayValue": null,             
            "depthValue": null,             
            "distanceValue": null 
...........}

...只保留myValue 字段。

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

【问题讨论】:

    标签: specifications operation jolt


    【解决方案1】:

    要从内部数组中删除 null,最后使用下面的代码

    {
        "operation": "modify-overwrite-beta",
        "spec": {
          "*": "=recursivelySquashNulls"
        }
    }
    

    【讨论】:

    【解决方案2】:

    这是可能的,只是不容易或直截了当。需要两个步骤。

    规格

    [
      {
        "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"
            }
          }
        }
      }
    ]
    

    生产

    {
      "myValue" : 345
    }
    

    【讨论】:

    猜你喜欢
    • 2022-11-24
    • 2022-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-23
    • 2022-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多