`
tonynju
  • 浏览: 75486 次
  • 性别: Icon_minigender_1
  • 来自: 浙江嘉善
社区版块
存档分类
最新评论

JSONPath - XPath for JSON

阅读更多
可以用于通过路径解析JSON对象的一个函数
主页:http://goessner.net/articles/JsonPath/

和XPath的使用对比
    XPath       JSONPath    Description
    /           $           the root object/element
    .           @           the current object/element
    /           . or []     child operator
    ..          n/a         parent operator
    //          ..          recursive descent. JSONPath borrows this syntax from E4X.
    *           *           wildcard. All objects/elements regardless their names.
    @           n/a         attribute access. JSON structures don't have attributes.
    []          []          subscript operator. XPath uses it to iterate over element collections and for predicates. In Javascript and JSON it is the native array operator.
    |           [,]         Union operator in XPath results in a combination of node sets. JSONPath allows alternate names or array indices as a set.
    n/a         [start:end:step]    array slice operator borrowed from ES4.
    []          ?()         applies a filter (script) expression.
    n/a         ()          script expression, using the underlying script engine.
    ()          n/a         grouping in Xpath
   
   
   
    { "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
        }
      }
    }
   
    XPath                   JSONPath                Result
    /store/book/author      $.store.book
  • .author  the authors of all books in the store
  •     //author                $..author               all authors
        /store/*                $.store.*               all things in store, which are some books and a red bicycle.
        /store//price           $.store..price          the price of everything in the store.
        //book[3]               $..book[2]              the third book
        //book[last()]          $..book[(@.length-1)]
                                $..book[-1:]            the last book in order.
        //book[position()<3]    $..book[0,1]
                                $..book[:2]             the first two books
        //book[isbn]            $..book[?(@.isbn)]      filter all books with isbn number
        //book[price<10]        $..book[?(@.price<10)]  filter all books cheapier than 10
        //*                     $..*                    all Elements in XML document. All members of JSON structure.

    分享到:
    评论

    相关推荐

      Python库 | jsonpath2-0.4.3-py3-none-any.whl

      JSONPath是类似于XPath(XML路径语言)的一种语法,专门用于查询JSON数据。它提供了一种简洁的表达式来定位JSON对象中的特定元素或值。例如,`$.store.book[0].title`可以用来获取JSON结构中第一个书的标题。`...

      Python使用jsonpath-rw模块处理Json对象操作示例

      `jsonpath`是一种类似于XPath的查询语言,专门用来在JSON数据中查找信息。然而,Python标准库并没有提供jsonpath,而是提供了`jsonpath-rw`这个第三方库。这个库提供了对JSON数据的灵活查询,让你能够像使用CSS选择...

      jsonpath-ng:最后,一个旨在符合标准的Python JSONPath实现。 就这样。 好好享受

      JSONPath是一种查询语言,用于在JSON文档中查找数据,类似于XPath在XML文档中的作用。它为程序员提供了一种简洁的方式来提取和操作嵌套JSON结构中的数据。Python中的`jsonpath-ng`库是一个遵循JSONPath规范的实现,...

      json-querying-performance-testing:测试可以用字符串查询json的npm软件包的性能

      测试的库是: 包裹NPM下载最后提交 映射过滤器减少 jsonpath-plus和jsonpath使用XPath for Json Specification 。 json-query具有自己的自定义DSL。 JSONStream , oboe和map-filter-reduce是流媒体库,尽管我在使...

      JSON入门Java篇-2-JSON数据类型.rar

      JSONPath是类似于XPath的JSON查询语言,用于从JSON文档中提取数据。JSONSchema则是一种JSON格式的规范,用于定义JSON数据的结构和验证。 6. JSON在Web服务中的应用: JSON常用于RESTful API的数据交互,作为HTTP...

      JSONPath:PHP的JSONPath实现

      JSONPath是一种类似于XPath的表达语言,用于过滤,展平和提取数据。 该项目旨在成为一个干净而简单的实现,其目标如下: 面向对象的代码(将来应该更易于管理或扩展) 使用Doctrine Lexer启发的代码将表达式解析为...

      15-Python正则表达式&jsonpath应用

      接着,我们转向**JSONPath**,这是一个类似于XPath的查询语言,专门用于从JSON数据中提取信息。在Python中,我们可以使用`jsonpath-ng`或`jsonpath_rw`等库来实现JSONPath的功能。比如,`jsonpath-ng`的`jsonpath`...

      Java API for JSON Processing (JSON-P).zip

      Java API for JSON Processing (JSON-P) 是Java平台上的一个标准API,用于处理JSON(JavaScript Object Notation)数据。这个API提供了在Java应用程序中解析、生成、修改和转换JSON的工具,使得开发人员能够方便地与...

      JsonPath2.4.0及其依赖包

      &lt;artifactId&gt;json-path &lt;version&gt;2.4.0 ``` 然后,你可以使用JsonPath提供的API来进行JSON操作。比如,以下代码演示了如何使用JsonPath从JSON字符串中提取数据: ```java import com.jayway.jsonpath.JsonPath;...

      Python json模块与jsonpath模块区别详解

      XPath 主要用于 XML 文档,而 JsonPath 专为 JSON 设计,允许开发者通过路径表达式来查询 JSON 数据,从而更加方便地获取所需的信息。 **2. 安装 jsonpath 模块** 由于 `jsonpath` 不是 Python 内置的模块,需要...

      json处理总结.zip

      JSON-P(Java API for JSON Processing)和JSON-B(Java Binding for JSON)是Java EE标准的一部分,提供了一种标准化的方式来处理JSON。 6. **JSON Schema** JSON Schema是一种JSON格式的规范,用于验证JSON数据...

      json相关jar包

      JSON-P(Java API for JSON Processing)是Java的一个标准,提供了处理JSON的API,包括解析、生成、操作JSON数据。 7. **JSON-Simple** 这是一个简单的Java库,用于读写JSON,适用于对性能要求不高但希望代码简洁...

      Json解析7个完整架包

      Jackson还支持JSON-P(Java API for JSON Processing)和JSON-B(Java Binding API for JSON)标准。 2. **Gson**: Google开发的Gson库允许将Java对象转换为JSON字符串,反之亦然。它的主要优势在于简单易用,且...

      Python爬虫JSON及JSONPath运行原理详解

      接下来,JSONPath是一种从JSON文档中提取特定信息的语言,类似于XPath在XML中的作用。它允许我们通过路径表达式选取JSON对象的特定部分。例如,如果我们有一个JSON对象包含一个数组,我们可以使用`$[index]`来选择...

      Java XML and JSON: Document Processing for Java SE, 2nd Edition

      New in this edition is coverage of Jackson (a JSON processor for Java) and Oracle’s own Java API for JSON processing (JSON-P), which is a JSON processing API for Java EE that also can be used with ...

      org.json.jar.zip

      org.json.jar库还提供了JSONPath的支持,这是一种类似于XPath的查询语言,用于在JSON结构中查找特定的数据。这对于大数据分析或复杂JSON对象的提取非常有用。 4. **集成到项目** 要在项目中使用org.json.jar,...

      jsonexplained,2019年JSON技术讲座的代码示例.zip

      8. JSON-LD (JSON for Linking Data):一种使用JSON表示语义网数据的标准,增强了数据的上下文和链接能力。 9. JSONPath:类似XPath的查询语言,用于从JSON文档中提取数据。 10. JSON库:如Python的`json`模块,...

      JSON依赖源码及各种资料

      7. JSON-LD:JSON for Linked Data,用于在Web上链接数据,支持语义网和Linked Open Data。 8. 在RESTful API中,JSON是主要的数据交换格式,用于请求和响应体。 了解并掌握这些知识点,可以有效地在开发过程中处理...

      jsonpath相关jar包已通过自己的测试

      JSONPath是一种用于提取和过滤JSON数据的表达式语言,类似于XPath对于XML的作用。在这个场景中,我们关注的是与JSONPath相关的Java库,这些库在给定的压缩包文件中已经通过了测试。以下是对这些库的详细介绍: 1. *...

      常用的9个json的jar包

      4. **JSON-P (JSR 353)** 和 **JSON-B (JSR 367)**:这两个是Java EE标准的一部分,分别提供了编程API和绑定API,用于处理JSON数据。它们为服务器端开发提供了标准化的解决方案。 5. **Apache JSON-Bridge**:...

    Global site tag (gtag.js) - Google Analytics