【问题标题】:JsonPath: How to get the whole tree except one nodeJsonPath:如何获取除一个节点外的整棵树
【发布时间】:2021-07-19 07:29:24
【问题描述】:

每个人。

我想我的问题很简单。

我的用例:

Jenkins 从 Gitlab WebHook 接收到一个巨大的 JSON 负载(超过 2500 行)。我想摆脱超过 2000 行的特定节点。我得到的 JSON 太大了,Jenkins 无法正确解析它,所以我想删除一个我不需要的节点。

假设documentation page中的样本树:

{
    "store": {
        "book": [
            {
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century",
                "price": 8.95
            },
            {
                "category": "fiction",
                "author": "Evelyn Waugh",
                "title": "Sword of Honour",
                "price": 12.99
            },
            {
                "category": "fiction",
                "author": "Herman Melville",
                "title": "Moby Dick",
                "isbn": "0-553-21311-3",
                "price": 8.99
            },
            {
                "category": "fiction",
                "author": "J. R. R. Tolkien",
                "title": "The Lord of the Rings",
                "isbn": "0-395-19395-8",
                "price": 22.99
            }
        ],
        "bicycle": {
            "color": "red",
            "price": 19.95
        }
    },
    "expensive": 10
}

除了一棵树外,我怎样才能得到整棵树?例如,如果我想获取除 book 节点之外的所有内容...

{
    "store": {
        "bicycle": {
            "color": "red",
            "price": 19.95
        }
    },
    "expensive": 10
}

我或多或少地了解过滤器功能,并且我认为我需要找出一个合适的过滤器,但似乎它们仅对根据某些条件搜索节点有用。我不确定它们是否有助于根据过滤条件删除元素。

非常感谢您的帮助。

【问题讨论】:

    标签: java jsonpath


    【解决方案1】:

    JSON Path 是一种查询工具,而不是操纵工具。您将无法使用它更改输入值。你需要另一个工具。

    我建议查看 https://jsonnet.org/ 之类的东西,它专为基于模板的转换和生成而设计。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-07
      • 1970-01-01
      • 2017-06-12
      • 1970-01-01
      相关资源
      最近更新 更多