• 文库
  • 字符
  • 转换
  • 加密
  • 网络
  • 更多
    图表
    数学
    坐标
    图片
    文件
  • 文库
    字符
    转换
    加密
    网络
    更多
    图表
    数学
    坐标
    图片
    文件
logo 在线工具大全
7 评论 收藏 复制链接 分享

在线JSONPath解析器


1. 在浏览器中执行查询 2. 部分语法支持可能不够完善

输入JSON

输出结果

在线JSONPath解析器-工具简介

JSONPath在线解析器,提供JSONPath在线运行功能。你可以输入JSON数据,然后使用JSONPath提取JSON中的数据。

在线JSONPath解析器-使用说明

在线 JSONPath 测试工具,输入 JSON 数据,使用 JSONPath 语法,提取 JSON 数据。JSONPath 查询支持浏览器 JavaScript 引擎, 服务器端 Java 引擎。

  1. JSONPath 语法规范
  2. 引擎:选择使用 JavaScript 引擎,还是 Java 引擎执行 JSONPath 查询。 JavaScript 引擎:在浏览器中执行查询,数据不会被上传到云端,部分语法支持不够完善。 Java 引擎:在服务器中执行查询,语法支持完善,功能强大。
  3. JSONPath:输入 JSONPath 查询语句,语法参考见下方文档。
  4. 本工具 Java 引擎有一定的使用频率限制,请合理使用本工具。 游客:120次/IP*小时,普通用户:120次/小时,VIP:720次/小时,高级VIP:720次/小时。
  5. JavaScript 引擎语法参考文档:
    JSONPath 结果 说明
    $.store.book[*].author store中所有book的author Can also be represented without the $. as store.book[*].author (though this is not present in the original spec); note that some character literals ($ and @) require escaping, however
    $..author 所有author
    $.store.* store属性的所有值
    $.store..price store下所有的price
    $..book[2] 第三个book对象
    $..book[(@.length-1)]
    $..book[-1:]
    最后一个book对象 To access a property with a special character, utilize [(@['...'])] for the filter (this particular feature is not present in the original spec)
    $..book[0,1]
    $..book[:2]
    前两个book对象
    $..book[0][category,author] 第一个book对象的category,author
    $..book[?(@.isbn)] 选择有isbn属性的book To access a property with a special character, utilize [?@['...']] for the filter (this particular feature is not present in the original spec)
    $..book[?(@.price<10)] 选择所有价格小于10的book
    $..*[?(@property === 'price' && @ !== 8.95)] 选择有price属性,且price属性值不等于8.95的对象的所有price属性值 With the bare @ allowing filtering objects by property value (not necessarily within arrays), you can add ^ after the expression to get at the object possessing the filtered properties
    $ JSON数据的根,整个JSON数据 To get a literal $ (by itself or anywhere in the path), you must use the backtick escape
    $..* 所有元素
    $.. 所有的父元素,包含root This behavior was not directly specified in the original spec
    $..[?(@.price>19)]^ Parent of those specific items with a price greater than 19 (i.e., the store value as the parent of the bicycle and the book array as parent of an individual book) Parent (caret) not present in the original spec
    $.store.*~ The property names of the store sub-object ("book" and "bicycle"). Useful with wildcard properties. Property name (tilde) is not present in the original spec
    $.store.book[?(@path !== "$['store']['book'][0]")] All books besides that at the path pointing to the first @path not present in the original spec
    $..book[?(@parent.bicycle && @parent.bicycle.color === "red")].category Grabs all categories of books where the parent object of the book has a bicycle child whose color is red (i.e., all the books) @parent is not present in the original spec
    $..book.*[?(@property !== "category")] Grabs all children of "book" except for "category" ones @property is not present in the original spec
    $..book[?(@property !== 0)] Grabs all books whose property (which, being that we are reaching inside an array, is the numeric index) is not 0 @property is not present in the original spec
    $.store.*[?(@parentProperty !== "book")] Grabs the grandchildren of store whose parent property is not book (i.e., bicycle's children, "color" and "price") @parentProperty is not present in the original spec
    $..book.*[?(@parentProperty !== 0)] Get the property values of all book instances whereby the parent property of these values (i.e., the array index holding the book item parent object) is not 0 @parentProperty is not present in the original spec
    $..book[?(@.price === @root.store.book[2].price)] Filter all books whose price equals the price of the third book @root is not present in the original spec
    $..book..*@number() Get the numeric values within the book array @number(), the other basic types (@boolean(), @string()), other low-level derived types (@null(), @object(), @array()), the JSONSchema-added type, @integer(), the compound type @scalar() (which also accepts undefined and non-finite numbers for JavaScript objects as well as all of the basic non-object/non-function types), the type, @other(), to be used in conjunction with a user-defined callback (see otherTypeCallback) and the following non-JSON types that can nevertheless be used with JSONPath when querying non-JSON JavaScript objects (@undefined(), @function(), @nonFinite()) are not present in the original spec
    $..book.*[?(@property === "category" && @.match(/TION$/i))] All categories of books which match the regex (end in 'TION' case insensitive) @property is not present in the original spec.
    $..book.*[?(@property.match(/bn$/i))]^ All books which have a property matching the regex (end in 'TION' case insensitive) @property is not present in the original spec. Note: Uses the parent selector ^ at the end of the expression to return to the parent object; without the parent selector, it matches the two isbn key values.
    ` (e.g., `$ to match a property literally named $) Escapes the entire sequence following (to be treated as a literal) ` is not present in the original spec; to get a literal backtick, use an additional backtick to escape
  6. Java 引擎语法参考文档:
    1. 操作符
      Operator Description
      $ The root element to query. This starts all path expressions.
      @ The current node being processed by a filter predicate.
      * Wildcard. Available anywhere a name or numeric are required.
      .. Deep scan. Available anywhere a name is required.
      .<name> Dot-notated child
      ['<name>' (, '<name>')] Bracket-notated child or children
      [<number> (, <number>)] Array index or indexes
      [start:end] Array slice operator
      [?(<expression>)] Filter expression. Expression must evaluate to a boolean value.
    2. 函数:函数可以在 JSONPath 路径的末尾调用——函数的输入是路径表达式的输出。函数输出由函数本身决定。
      Function Description Output type
      min() Provides the min value of an array of numbers Double
      max() Provides the max value of an array of numbers Double
      avg() Provides the average value of an array of numbers Double
      stddev() Provides the standard deviation value of an array of numbers Double
      length() Provides the length of an array Integer
      sum() Provides the sum value of an array of numbers Double
      keys() Provides the property keys (An alternative for terminal tilde ~) Set<E>
      concat(X) Provides a concatinated version of the path output with a new item like input
      append(X) add an item to the json path output array like input
      first() Provides the first item of an array Depends on the array
      last() Provides the last item of an array Depends on the array
      index(X) Provides the item of an array of index: X, if the X is negative, take from backwards Depends on the array
    3. 过滤操作符:Filters are logical expressions used to filter arrays. A typical filter would be [?(@.age > 18)] where @ represents the current item being processed. More complex filters can be created with logical operators && and ||. String literals must be enclosed by single or double quotes ([?(@.color == 'blue')] or [?(@.color == "blue")]).
      Operator Description
      == left is equal to right (note that 1 is not equal to '1')
      != left is not equal to right
      < left is less than right
      <= left is less or equal to right
      > left is greater than right
      >= left is greater than or equal to right
      =~ left matches regular expression [?(@.name =~ /foo.*?/i)]
      in left exists in right [?(@.size in ['S', 'M'])]
      nin left does not exists in right
      subsetof left is a subset of right [?(@.sizes subsetof ['S', 'M', 'L'])]
      anyof left has an intersection with right [?(@.sizes anyof ['M', 'L'])]
      noneof left has no intersection with right [?(@.sizes noneof ['M', 'L'])]
      size size of left (array or string) should match right
      empty left (array or string) should be empty
    4. JSONPath 示例
      JsonPath Result
      $.store.book[*].author The authors of all books
      $..author All authors
      $.store.* All things, both books and bicycles
      $.store..price The price of everything
      $..book[2] The third book
      $..book[-2] The second to last book
      $..book[0,1] The first two books
      $..book[:2] All books from index 0 (inclusive) until index 2 (exclusive)
      $..book[1:2] All books from index 1 (inclusive) until index 2 (exclusive)
      $..book[-2:] Last two books
      $..book[2:] All books from index 2 (inclusive) to last
      $..book[?(@.isbn)] All books with an ISBN number
      $.store.book[?(@.price < 10)] All books in store cheaper than 10
      $..book[?(@.price <= $['expensive'])] All books in store that are not "expensive"
      $..book[?(@.author =~ /.*REES/i)] All books matching regex (ignore case)
      $..* Give me every thing
      $..book.length() The number of books

示例JSON数据 复制

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