使用JSONPath提取属性的子集 [英] Extracting a subset of attributes with JSONPath

查看:113
本文介绍了使用JSONPath提取属性的子集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下JSON代码:

I have this JSON code:

{
    "A": {
        "AB": [{
            "ABA": "0",
            "ABB": "1",
            "ABC": "2"
        }]
    }
}

我需要使用一个JSONPath表达式,该表达式仅返回具有ABA和ABC属性的JSON.像这样:

I need to use a JSONPath expression that returns that JSON with only ABA and ABC attributes. Something like:

{
    "A": {
        "AB": [{
            "ABA": "0",
            "ABC": "2"
        }]
    }
}

到目前为止,我设法提取一个或所有属性.例如

So far I manage to extract either one or all attributes. For example

$.A.AB[*]

$.A.AB[*].ABA

有没有办法只提取两个?

Is there a way to extract only two?

谢谢

推荐答案

这将使用Jayway实现(Java)进行工作:

This will work using the Jayway implementation (Java):

$.A.AB[*]['ABB', 'ABA']

,您输入的结果将是:

[
   {
      "ABB" : "1",
      "ABA" : "0"
   }
]

您可以在此处比较其他提供商:

You can Compare different providers here:

http://jsonpath.herokuapp.com/

这篇关于使用JSONPath提取属性的子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆