Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of contents

Expand
titleClick here to expand the table of contents
Table of Contents

...

Description

The tool is designed to validate data in XPath / JSONPath format and help in writing correct expressions for parsing data from XML and JSON documents.

...

The Beautify button allows you to automatically format the code and bring it to an easy-to-read format.

...

Basic XPath syntax.

Expression

Result

hostname

Selects all nodes named "node_name"

/

Selects from root node

//

Selects nodes from the current node matching the selection, regardless of their location

.

Selects the current node

..

Selects the parent of the current node

@

Selects attributes

Special characters are used to search for unknown nodes:

Special character

Description

*

Matches any element node

@*

Matches any attribute node

node()

Matches any node of any type

...

Basic JSONPath syntax.

Expression

Result

$

Selects from root node

..

Parent operator

... or []

Descendant operator

..

Selects nodes from the current node matching the selection

@

Selects the current node

?()

Applies a filter expression

Examples:

Code Block
languagejson
{ "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

“author” elements of all “book” elements in “store”

//author

$..author

all “author” elements

/store/*

$.store.*

all content in "store"

/store//price

$.store..price

the value of the price of the "price" element of all elements in the "store"

//book[3]

$..book[2]

third element "book"

//book[last()]

$..book[(@.length-1)]
$..book[-1:]

the last element "book"

//book[position()<3]

$..book[0,1]
$..book[:2]

the first 2 elements of "book"

//book[isbn]

$..book[?(@.isbn)]

filter all elements of “book” with value “isbn”

//book[price<10]

$..book[?(@.price<10)]

filter all “book” elements with “price” value less than 10

//*

$..*

all elements in the XML document. All members of the JSON structure.