json_path Method


result = json_path(json, path)


jsonstringJSON Object

The JSON definition, defined as a string or JSON Object.


The path defining what portion of the JSON to extract.


resultJSON Object

Returns the portion of the JSON that matches the path.


Extracts a portion of a JSON string or object.


The json_path() method allows you to extract portions of a JSON string and perform certain types of simple calculations on a JSON string.

The json_path() method is only available in the UX component. In addition, you must explicitly load the jsonpath system library by selecting it at the Optional system libraries property in the UX Builder if you want to use the json_path() method in your code.

The example below extracts the "book" array from the JSON object:

var path = '$[*]';

var 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

var result = json_path(json,path);


The chart below describes what will be returned by the json_path() method for the specified path. The examples in this chart are from the NPM JSONPath documentation:

JSON Path Syntax



The authors of all books in the store


All authors


All things in store, which are its books (a book array) and a red bicycle (a bicycle object).


The price of everything in the store.


The third book (book object)


The last book in order.



The first two books



The categories and authors of all books


Filter all books with an ISBN number


Filter all books cheaper than 10

$..*[?(@property === 'price' && @ !== 8.95)]

Obtain all property values of objects whose property is price and which does not equal 8.95


The root of the JSON object (i.e., the whole object itself)


All Elements (and text) beneath root in an XML document. All members of a JSON structure beneath the root.


All Elements in an XML document. All parent components of a JSON structure including root.


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)


The property names of the store sub-object ("book" and "bicycle"). Useful with wildcard properties.

$[?(@path !== "$['store']['book'][0]")]

All books besides that at the path pointing to the first

$[?(@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)

$*[?(@property !== "category")]

Grabs all children of "book" except for "category" ones

$[?(@property !== 0)]

Grabs all books whose property (which, being that we are reaching inside an array, is the numeric index) is not 0

$.store.*[?(@parentProperty !== "book")]

Grabs the grandchildren of store whose parent property is not book (i.e., bicycle's children, "color" and "price")

$*[?(@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


Get the numeric values within the book array

json_path in Xbasic 

You can also use JSON Path in server-side scripts (in your Xbasic code). The Xbasic function is also called json_path().

See Also