You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Jolt移除JSON根层级的null元素?

使用Jolt移除JSON根层级的null元素

需求

仅移除JSON根层级值为null的键值对,嵌套层级或数组内的null元素保留原样。

输入示例

{
  "x": null,
  "y": null,
  "z": [
    {
      "id": "1",
      "name": "2",
      "price": null,
      "quantity": 1
    }
  ]
}

期望输出

{
  "z": [
    {
      "id": "1",
      "name": "2",
      "price": null,
      "quantity": 1
    }
  ]
}

Jolt转换规范

[
  {
    "operation": "remove",
    "spec": {
      "*": {
        "$": ["=null"]
      }
    }
  }
]

规范解释

  • operation: "remove":明确当前操作为移除元素
  • *:匹配根层级的所有键
  • "$": ["=null"]:仅当键对应的值为null时执行移除操作,精准定位根层级的null元素,不会干扰子结构内的null值

内容的提问来源于stack exchange,提问作者Datadev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 16:39:52