Try it Out!

Enter an expression in the search box to see JMESPath in action.

The expression is evaluated against the JSON data and the result is shown in the result pane.

To learn more about JMESPath, check out the Tutorial and Examples

Have questions? Come chat with us

Have a feature request? Contribute

Complete ABNF Specification

The JMESPath language is described in an ABNF grammar with a complete specification. This ensures that the language syntax is precisely defined.

Compliance Test Suite

JMESPath has a full suite of data driven testcases. This ensures parity for multiple libraries, and makes it easy for developers to implement JMESPath in their language of choice.

Libraries in Multiple Languages

Each JMESPath library passes a complete suite of compliance tests to ensure they work as intended. There are libraries in multiple languages including python, php, javascript and lua.

Tutorial

JMESPath is a query language for JSON. You can extract and transform elements from a JSON document. The examples below are interactive. You can change the JMESPath expressions and see the results update automatically.

For each of these examples, the JMESPath expression is applied to the input JSON on the left, and the result of evaluating the JMESPath expression is shown in the JSON document on the right-hand side.

Basic Expressions

The simplest JMESPath expression is an identifier, which selects a key in an JSON object:

Try changing the expression above to b, and c and note the updated result. Also note that if you refer to a key that does not exist, a value of null (or the language equivalent of null) is returned.

You can use a subexpression to return to nested values in a JSON object:

If you refer to a key that does not exist, a value of null is returned. Attempting to subsequently access identifiers will continue to return a value of null. Try changing the expression to b.c.d.e above.

Index Expressions allow you to select a specific element in a list. It should look similar to array access in common programming languages. Indexing is 0 based.

If you specify an index that’s larger than the list, a value of null is returned. You can also use negative indexing to index from the end of the list. [-1] refers to the last element in the list, [-2] refers to the penultimate element. Try it out in the example above.

You can combine identifiers, sub expressions, and index expressions to access JSON elements.

Slicing

Slices allow you to select a contiguous subset of an array. If you’ve ever used slicing in python, then you already know how to use JMESPath slices. In its simplest form, you can specify the starting index and the ending index. The ending index is the first index which you do not want included in the slice. Let’s take a look at some examples. First, given an array of integers from 0 to 9, let’s select the first half of the array:

This slice result contains the elements 0, 1, 2, 3, and 4. The element at index 5 is not included. If we want to select the second half of the array, we can use this expression:

The two example above can be shortened. If the start or stop value is omitted it is assumed to be the start or the end of the array. For example:

Try modifying the example above to only include the last half of the array elements without specifying the end value of 10.

The general form of a slice is [start:stop:step]. So far we’ve looked at the [start:stop] form. By default, the step value is 1, which means to include every element in the range specified by the start and stop value. However, we can use the step value to skip over elements. For example, to select only the even elements from the array.

Also note in this example we’re omitting the start as well as the stop value, which means to use 0 for the start value, and 10 for the stop value. In this example, the expression [::2] is equivalent to [0:10:2].

The last thing to know about slices is that just like indexing a single value, all the values can be negative. If the step value is negative, then the slice is created in reverse order. For example:

The above expression creates a slice but in reverse order.

If you want all the details about how slices work, check out the slices in the specification.

Projections

Projections are one of the key features of JMESPath. It allows you to apply an expression to a collection of elements. There are five kinds of projections:

List and Slice Projections

A wildcard expression creates a list projection, which is a projection over a JSON array. This is best illustrated with an example. Let’s say we have a JSON document describing a people, and each array element is a JSON object that has a first, last, and age key. Suppose we wanted a list of all the first names in our list.

In the example above, the first expression, which is just an identifier, is applied to each element in the people array. The results are collected into a JSON array and returned as the result of the expression. The expression can be more complex than a basic identifier. For example, the expression foo[*].bar.baz[0] would project the bar.baz[0] expression to each element in the foo array.

There’s a few things to keep in mind when working with projections. These are discussed in more detail in the [wildcards] section of the spec, but the main points are:

You can try this out in the demo above. Notice how people[*].first only included three elements, even though the people array has four elements. This is because the last element, {"missing": "different"} evaluates to null when the expression first is applied, and null values are not added to the collected result array. If you try the expression foo[*].bar you’ll see a result of null, because the value associated with the foo key is a JSON object, not an array, and a list projection is only defined for JSON arrays.

Slice projections are almost identical to a list projection, with the exception that the left-hand side is the result of evaluating the slice, which may not include all the elements in the original list:

Object Projections

Whereas a list projection is defined for a JSON array, an object projection is defined for a JSON object. You can create an object projection using the * syntax. This will create a list of the values of the JSON object, and project the right-hand side of the projection onto the list of values.

In the example above the * creates a JSON array of the values associated with the ops JSON object. The RHS of the projection, numArgs, is then applied to the JSON array, resulting in the final array of [2, 3]. Below is a sample walk-through of how an implementation could potentially implement evaluating an object projection. First, the object projection can be broken down into its two components, the left-hand side (LHS) and its right-hand side (RHS):

First, the LHS is evaluated to create the initial array to be projected:

evaluate(ops, inputData) -> [{"numArgs": 2}, {"numArgs": 3},
                             {"variadic": True}]

Then the RHS is applied to each element in the array:

evaluate(numArgs, {numArgs: 2}) -> 2
evaluate(numArgs, {numArgs: 3}) -> 3
evaluate(numArgs, {variadic: true}) -> null

Any null values are not included in the final result, so the result of the entire expression is therefore [2, 3].

Flatten Projections

More than one projection can be used in a JMESPath expression. In the case of a List/Object projection, the structure of the original document is preserved when creating projection within a projection. For example, let’s take the expression reservations[*].instances[*].state. This expression is saying that the top level key reservations has an array as a value. For each of those array elements, project the instances[*].state expression. Within each list element, there’s an instances key which itself is a value, and we create a sub projection for each each list element in the list. Here’s an example of that:

The result of this expression is [["running", "stopped"], ["terminated", "running"]], which is a list of lists. The outer list is from the projection of reservations[*], and the inner list is a projection of state created from instances[*]:

1st       r0                         r1
2nd i0          i1             i0            i1
[["running", "stopped"], ["terminated", "running"]]

What if we just want a list of all the states of our instances? We’d ideally like a result ["running", "stopped", "terminated", "running"]. In this situation, we don’t care which reservation the instance belonged to, we just want a list of states.

This is the problem that a Flatten Projection solves. To get the desired result, you can use [] instead of [*] to flatten a list: reservations[].instances[].state. Try changing [*] to [] in the expression above and see how the result changes.

While the flatten spec goes into more detail, a simple rule of thumb to use for the flatten operator, [], is that:

You can also just use [] on its own to flatten a list:

If you flattened the result of the expression again, [][], you’d then get a result of [0, 1, 2, 3, 4, 5, 6, 7]. Try it out in the example above.

Filter Projections

Up to this point we’ve looked at:

Evaluating the RHS of a projection is a basic type of filter. If the result of the expression evaluated against an individual element results in null, then the element is excluded from the final result.

A filter projection allows you to filter the LHS of the projection before evaluating the RHS of a projection.

For example, let’s say we have a list of machines, each has a name and a state. We’d like the name of all machines that are running. In pseudocode, this would be:

result = []
foreach machine in inputData['machines']
  if machine['state'] == 'running'
    result.insert_at_end(machine['name'])
return result

A filter projection can be used to accomplish this:

Try changing running to stopped in the example above. You can also remove the .name at the end of the expression if you just want the entire JSON object of each machine that has the specified state.

A filter expression is defined for an array and has the general form LHS [? <expression> <comparator> <expression>] RHS. The filter expression <filterexpressions>{.interpreted-text role=“ref”} spec details exactly what comparators are available and how they work, but the standard comparators are supported, i.e ==, !=, <, <=, >, >=.

Pipe Expressions

Projections are an important concept in JMESPath. However, there are times when projection semantics are not what you want. A common scenario is when you want to operate of the result of a projection rather than projecting an expression onto each element in the array. For example, the expression people[*].first will give you an array containing the first names of everyone in the people array. What if you wanted the first element in that list? If you tried people[*].first[0] that you just evaluate first[0] for each element in the people array, and because indexing is not defined for strings, the final result would be an empty array, []. To accomplish the desired result, you can use a pipe expression, <expression> | <expression>, to indicate that a projection must stop. This is shown in the example below:

In the example above, the RHS of the list projection is first. When a pipe is encountered, the result up to that point is passed to the RHS of the pipe expression. The pipe expression is evaluated as:

evaluate(people[*].first, inputData) -> ["James", "Jacob", "Jayden"]
evaluate([0], ["James", "Jacob", "Jayden"]) -> "James"

MultiSelect

Up to this point, we’ve looked at JMESPath expressions that help to pare down a JSON document into just the elements you’re interested in. This next concept, multiselect lists and multiselect hashes allow you to create JSON elements. This allows you to create elements that don’t exist in a JSON document. A multiselect list creates a list and a multiselect hash creates a JSON object.

This is an example of a multiselect list:

In the expression above, the [name, state.name] portion is a multiselect list. It says to create a list of two element, the first element is the result of evaluating the name expression against the list element, and the second element is the result of evaluating state.name. Each list element will therefore create a two element list, and the final result of the entire expression is a list of two element lists.

Unlike a projection, the result of the expression in always included, even if the result is a null. If you change the above expression to people[].[foo, bar] each two element list will be [null, null].

A multiselect hash has the same basic idea as a multiselect list, except it instead creates a hash instead of an array. Using the same example above, if we instead wanted to create a two element hash that had two keys, Name and State, we could use this:

Functions

JMESPath supports function expressions, for example:

Functions can be used to transform and filter data in powerful ways.

Below are a few examples of functions.

This example prints the name of the oldest person in the people array:

Functions can also be combined with filter expressions. In the example below, the JMESPath expressions finds all elements in myarray that contains the string foo.

The @ character in the example above refers to the current element being evaluated in myarray. The expression contains(@, `foo`) will return true if the current element in the myarray array contains the string foo.

While the function expression spec has all the details, there are a few things to keep in mind when working with functions:

Next Steps

We’ve now seen an overview of the JMESPath language. The next things to do are:

Examples

Filters and Multiselect Lists

One of the most common usage scenarios for JMESPath is being able to take a complex JSON document and simplify it down. The main features at work here are filters and multiselects. In this example below, we’re taking the array of people and, for any element with an age key whose value is greater than 20, we’re creating a sub list of the name and age values.

Filters and Multiselect Hashes

In the previous example we were taking an array of hashes, and simplifying down to an array of two element arrays containing a name and an age. We’re also only including list elements where the age key is greater than 20. If instead we want to create the same hash structure but only include the age and name key, we can instead say:

The last half of the above expression contains key value pairs which have the general form keyname: <expression>. In the above expression we’re just using a field as an expression, but they can be more advanced expressions. For example:

Notice in the above example instead of applying a filter expression ([? <expr> ]), we’re selecting all array elements via [*].

Working with Nested Data

The above example combines several JMESPath features including the flatten operator, multiselect lists, filters, and pipes.

The input data contains a top level key, “reservations”, which is a list. Within each list, there is an “instances” key, which is also a list.

The first thing we’re doing here is creating a single list from multiple lists of instances. By using the flatten we can take the two instances from the first list and the two instances from the second list, and combine them into a single list. Try changing the above expression to just reservations[].instances[] to see what this flattened list looks like. Everything to the right of the reservations[].instances[] is about taking the flattened list and paring it down to contain only the data that we want. This expression is taking each element in the original list and transforming it into a three element sublist. The three elements are:

The most interesting of those three expressions is the tags[?Key=='Name'].Values[] | [0] part. Let’s examine that further.

The first thing to notice is that we’re filtering down the list associated with the tags key. The tags[?Key==`Name`] tells us to only include list elements that contain a Key whose value is Name. From those filtered list elements we’re going to take the Values key and flatten the list. Finally, the | [0] will take the entire list and extract the 0th element.

Filtering and Selecting Nested Data

In this example, we’re going to look at how you can filter nested hashes.

In this example we’re searching through the people array. Each element in this array contains a hash of two elements, and each value in the hash is itself a hash. We’re trying to retrieve the value of the general key that contains an id key with a value of 100.

If we just had the expression people[?general.id==`100`], we’d have a result of:

[{
  "general": {
    "id": 100,
    "age": 20,
    "other": "foo",
    "name": "Bob"
  },
  "history": {
    "first_login": "2014-01-01",
    "last_login": "2014-01-02"
  }
}]

Let’s walk through how we arrived at this result. In words, the people[?general.id==`100`] expression is saying “for each element in the people array, select the elements where the general.id equals 100”. If we trace the execution of this filtering process we have:

# First element:
    {
      "general": {
        "id": 100,
        "age": 20,
        "other": "foo",
        "name": "Bob"
      },
      "history": {
        "first_login": "2014-01-01",
        "last_login": "2014-01-02"
      }
    },
# Applying the expression ``general.id`` to this hash::
    100
# Does 100==100?
    true
# Add this first element (in its entirety) to the result list.

# Second element:
    {
      "general": {
        "id": 101,
        "age": 30,
        "other": "bar",
        "name": "Bill"
      },
      "history": {
        "first_login": "2014-05-01",
        "last_login": "2014-05-02"
      }
    }

# Applying the expression ``general.id`` to this element::
    101
# Does 101==100?
    false
# Do not add this element to the results list.
# Result of this expression is a list containing the first element.

However, this still isn’t the final value we want which is:

{
  "id": 100,
  "age": 20,
  "other": "foo",
  "name": "Bob"
}

In order to get to this value from our filtered results we need to first select the general key. This gives us a list of just the values of the general hash:

[{
  "id": 100,
  "age": 20,
  "other": "foo",
  "name": "Bob"
}]

From there, we then uses a pipe (|) to stop projections so that we can finally select the first element ([0]). Note that we are making the assumption that there’s only one hash that contains an id of 100. Given the way the data is structured, it’s entirely possible to have data such as:

{
  "people": [
    {
      "general": {
        "id": 100,
        "age": 20
      },
      "history": {
      }
    },
    {
      "general": {
        "id": 101,
        "age": 30
      },
      "history": {
      }
    },
    {
      "general": {
        "id": 100,
        "age": 30
      },
      "history": {
      }
    }
  ]
}

Note here that the first and last elements in the people array both have an id of 100. Our expression would then select the first element that matched.

Finally, it’s worth mentioning there is more than one way to write this expression. In this example we’ve decided that after we filter the list we’re going to select the value of the general key and then select the first element in that list. We could also reverse the order of those operations, we could have taken the filtered list, selected the first element, and then extracted the value associated with the general key. That expression would be:

people[?general.id==`100`] | [0].general

Both versions are equally valid.

Using Functions

JMESPath functions give you a lot of power and flexibility when working with JMESPath expressions. Below are some common expressions and functions used in JMESPath.

sort_by

The first interesting thing here if the use of the function sort_by. In this example we are sorting the Contents array by the value of each Date key in each element in the Contents array. The sort_by function takes two arguments. The first argument is an array, and the second argument describes the key that should be used to sort the array.

The second interesting thing in this expression is that the second argument starts with &, which creates an expression type. Think of this conceptually as a reference to an expression that can be evaluated later. If you are familiar with lambda and anonymous functions, expression types are similar. The reason we use &Date instead of Date is because if the expression is Date, it would be evaluated before calling the function, and given there’s no Date key in the outer hash, the second argument would evaluate to null. Check out function-evaluation{.interpreted-text role=“ref”} in the specification for more information on how functions are evaluated in JMESPath. Also, note that we’re taking advantage of the fact that the dates are in ISO 8601 format, which can be sorted lexicographically.

And finally, the last interesting thing in this expression is the [*] immediately after the sort_by function call. The reason for this is that we want to apply the multiselect hash, the second half of the expression, to each element in the sorted array. In order to do this we need a projection. The [*] does exactly that, it takes the input array and creates a projection such that the multiselect hash {Key: Key, Size: Size} will be applied to each element in the list.

There are other functions that take expression types that are similar to sort_by including min_by and max_by .

Pipes

Pipe expression are useful for stopping projections. They can also be used to group expressions.

Main Page

Let’s look at a modified version of the expression on the JMESPath front page .

We can think of this JMESPath expression as having three components, each separated by the pipe character |. The first expression is familiar to us, it’s similar to the first example on this page. The second part of the expression, sort(@), is similar to the sort_by function we saw in the previous section. The @ token is used to refer to the current element. The sort function takes a single parameter which is an array. If the input JSON document was a hash, and we wanted to sort the foo key, which was an array, we could just use sort(foo). In this scenario, the input JSON document is the array we want to sort. To refer to this value, we use the current element, @, to indicate this. We’re also only taking a subset of the sorted array. We’re using a slice ([-2:]) to indicate that we only want the last two elements in the sorted array to be passed through to the final third of this expression.

And finally, the third part of the expression, {WashingtonCities: join(', ', @)}, creates a multiselect hash. It takes as input, the list of sorted city names, and produces a hash with a single key, WashingtonCities, whose values are the input list (denoted by @) as a string separated by a comma.

Preview Features

Lexical Scopes

JMESPath Community introduces the let-expression function to supports nested lexical scopes.

let $foo = bar in {a: myvar, b: $foo}

The first argument is a JSON object that introduces a new lexical scope.

The second argument is an expression-type that is evaluated against the current context – i.e the current result of JMESPath evaluation context, that can be referred to by the @ node. The expression-type also has access to the stack of nested scopes.

Consider the following example:

When evaluating the states identifier, JMESPath no longer has access to the root scope, where first_choice is defined. Therefore, under normal circumstances, the filter-expression [?name === first_choice] would evaluate the first_choice identifier and return an empty array.

Instead, let() defined the identifier first_choice has taking the value of the property with the same name in the input JSON document. It effectively created a scope that can be represented as the following JSON object:

{ "first_choice": "WA" }

Therefore, when evaluating the filter-expression, the first_choice identifier is indeed defined, and produces the correct result.

Arithmetic Expressions

JMESPath Community now supports arithmetic-expression syntax with the usual operators.

Object Manipulation Functions

As a JSON query language, JMESPath Community now supports functions to manipulate JSON objects .

The items() function allows you to deconstruct a JSON object to its key and values, whereas the from_items() function will combine two arrays into a single JSON object.

The zip() function comes the Python language. It combines two or more arrays into a set of arrays, each of which contains the _i_th indexed item from each indivual array.

For better understanding, consider the following example:

Think of the three fruits, people and country arrays as being rows in a table. Each array has a number of items that you can think of as being the columns in the table.

The zip() function will create as many arrays as there are full columns, each of which will contain the items found in each row of the table.

So, the first array – corresponding to the first column of the table – will contain one item from the people row, one item from the country row and finally one item from the fruits row, resulting in ["John", "Germany", "Orange"].

The second array – corresponding to the second column of the table – contains ["Marc", "France", "Apple"].

String Slices

Using slice-expression to slice strings is popular in modern programming languages. JMESPath Community supports slicing strings using the same syntax:

Note: slice-expression applied to JSON arrays result in a projection. Applying a slice-expression to a JSON string, however, produces a JSON string.

Groups

Using the group_by() function , you can group collection of objects with specific criteria:

Libraries

The JMESPath specification is implemented in various languages. Each list below shows JMESPath libraries as well as the compliance level. The compliance level is based on which compliance tests the library can pass and as reported by their respective authors.

LanguageNameCompliance Level
C++jmespath.cppFully compliant
.NETjmespath.net
Elixirex-jmesFully compliant
Gogo-jmespath
Javajmespath-javaFully compliant
Luajmespath.luaFully compliant
Javascriptjmespath.jsFully compliant
PHPjmespath.phpFully compliant
Pythonpython-jmespath
Rubyjmespath.rbFully compliant
Rustjmespath.rsFully compliant
TypeScripttypescript-jmespath

In addition to the JMESPath libraries above, there are a number of miscellaneous JMESPath tools.

ToolDescription
jmespath.terminalProvides a JMESPath interactive terminal that you can use to evaluate JMESPath expressions as you type. The README in the github repo shows GIFs of jpterm in action.
jpProvides a JMESPath command line interface called jp. This cross platform tool accepts JSON data through stdin or input files, and prints the result of evaluating the JMESPath expression to stdout. This is useful if you're writing shell scripts that need to manipulate JSON data.

Syntax

In this specification, examples are shown through the use of a search function. The syntax for this function is:

search(<jmespath expr>, <JSON document>) -> <return value>

For simplicity, the jmespath expression and the JSON document are not quoted. For example:

search(foo, {"foo": "bar"}) -> "bar"

The result of applying a JMESPath expression against a JSON document will always result in valid JSON, provided there are no errors during the evaluation process. Structured data in, structured data out.

This also means that, with the exception of JMESPath expression types, JMESPath only supports the same types supported by JSON:

  • number (integers and double-precision floating-point format in JSON)
  • string (a sequence of Unicode code points . Note that a code point is distinct to a code unit )
  • boolean (true or false)
  • array (an ordered, sequence of values)
  • object (an unordered collection of key value pairs)
  • null

Expression types are discussed in the Function Expressions section.

Implementations can map the corresponding JSON types to their language equivalent. For example, a JSON null could map to None in python, and nil in ruby and go.

Errors

Errors may be raised during the JMEspath evaluation process. How and when errors are raised is implementation specific, but implementations should indicate to the caller when errors have occurred.

The following errors are defined:

  • invalid-arity is raised when an invalid number of function arguments is encountered during the evaluation process.
  • invalid-type is raised when an invalid type is encountered during the evaluation process.
  • invalid-value is raised when an invalid value is encountered during the evaluation process.
  • not-a-number is raised when arithmetic expressions overflow.
  • unknown-function is raised when an unknown function is encountered during the evaluation process.

Grammar

JMESPath grammar is specified using ABNF, as described in RFC4234

In addition to the grammar, there is the following token precedence that goes from weakest to tightest binding:

  • pipe: |
  • or: ||
  • and: &&
  • unary not: !
  • rbracket: ]

expression        = sub-expression / index-expression  / comparator-expression
expression        =/ or-expression / identifier
expression        =/ and-expression / not-expression / paren-expression
expression        =/ multi-select-list / multi-select-hash / literal
expression        =/ function-expression / pipe-expression / raw-string
expression        =/ root-node / current-node
expression        =/ arithmetic-expression
expression        =/ let-expression / variable-ref

sub-expression    = expression "." ( identifier / multi-select-list / multi-select-hash / function-expression / "*" ) 

pipe-expression   = expression "|" expression 

or-expression     = expression "||" expression 

and-expression    = expression "&&" expression 

not-expression    = "!" expression 

arithmetic-expression =/ "+" expression ; + %x43 
arithmetic-expression =/ ( "-" / "–" ) expression ; - %x45 – %x2212 \
arithmetic-expression = expression "%" expression ; % %x37 \
arithmetic-expression =/ expression ( "*" / "×" ) expression ; * %x42 ×  %xD7 \
arithmetic-expression =/ expression "+" expression ; + %x43 \
arithmetic-expression =/ expression ( "-" / "–" ) expression ; - %x45 – %x2212 \
arithmetic-expression =/ expression ( "/" / "÷" ) expression ; / %x47 ÷ %F7 \
arithmetic-expression = expression "//" expression ; // %47 %47

paren-expression  = "(" expression ")" 

index-expression  = expression bracket-specifier / bracket-specifier 
bracket-specifier = "[" (number / slice-expression) "]"

bracket-specifier =/ "[]" 

slice-expression  = [number] ":" [number] [ ":" [number] ] 

multi-select-list = "[" ( expression *( "," expression ) ) "]" 

multi-select-hash = "{" ( keyval-expr *( "," keyval-expr ) ) "}" 
keyval-expr       = identifier ":" expression

expression        =/ "*" 
bracket-specifier =/ "[" "*" "]"

filter-expression = "[?" expression "]" 
bracket-specifier =/ filter-expression 
comparator-expression = expression comparator expression 
comparator        = "<" / "<=" / "==" / ">=" / ">" / "!="

function-expression = unquoted-string  ( no-args  / one-or-more-args ) 
no-args             = "(" ")" 
one-or-more-args    = "(" ( function-arg *( "," function-arg ) ) ")" 
function-arg        = expression / expression-type 
current-node        = "@" 
root-node           = "$" 
expression-type     = "&" expression
let-expression = "let" bindings "in" expression 
bindings = variable-binding *( "," variable-binding ) \
variable-binding = variable-ref "=" expression \
variable-ref = "$" unquoted-string


raw-string        = "'" *raw-string-char "'" 
raw-string-char   = (%x00-26 / %x28-5B / %x5D-10FFFF) / preserved-escape / raw-string-escape 
preserved-escape  = escape (%x00-26 / %x28-5B / %x5D-10FFFF) 
raw-string-escape = escape ("'" / escape)

literal           = "`" json-text "`" 

number            = ["-"] 1*digit
digit             = %x30-39 ; 0-9
identifier        = unquoted-string / quoted-string 

unquoted-string   = (%x41-5A / %x61-7A / %x5F) *(  ; A-Za-z_
                        %x30-39  /  ; 0-9
                        %x41-5A /  ; A-Z
                        %x5F    /  ; _
                        %x61-7A)   ; a-z
quoted-string     = quotation-mark *(unescaped-char / escaped-char) quotation-mark
unescaped-char    = %x20-21 / %x23-5B / %x5D-10FFFF
escape            = %x5C   ; \
quotation-mark    = %x22   ; "
escaped-char      = escape (
                        %x22 /          ; "    quotation mark  U+0022
                        %x5C /          ; \    reverse solidus U+005C
                        %x2F /          ; /    solidus         U+002F
                        %x62 /          ; b    backspace       U+0008
                        %x66 /          ; f    form feed       U+000C
                        %x6E /          ; n    line feed       U+000A
                        %x72 /          ; r    carriage return U+000D
                        %x74 /          ; t    tab             U+0009
                        %x75 4HEXDIG )  ; uXXXX                U+XXXX

json-text  = ws json-value ws
ws         = *(
                %x20 /              ; Space
                %x09 /              ; Horizontal tab
                %x0A /              ; Line feed or New line
                %x0D )              ; Carriage return
; `json-value` is any valid JSON value with the one exception that each
; U+0060 GRAVE ACCENT '`' must be escaped with a preceding backslash.
; While implementations are encouraged to use any existing JSON parser for this
; section of the grammar (after handling the escaped characters), a complete
; set of rules derived from RFC 8259 is included below:
json-value = false / null / true / json-object / json-array /
             json-number / json-string
; JSON literals
false = %x66.61.6c.73.65   ; false
null  = %x6e.75.6c.6c      ; null
true  = %x74.72.75.65      ; true
; JSON strings
json-string    = quotation-mark *( json-unescaped / json-escaped ) quotation-mark
json-unescaped = %x20-21     / ; space or '!' (precedes U+0022 '"')
                 %x23-5B     / ; '#' through '[' (precedes U+005C '\')
                 %x5D-5F     / ; ']' through '_' (precedes U+0060 '`')
                 %x61-10FFFF   ; 'a' and all following code points
json-escaped   = escaped-char / (escape "`")
; JSON arrays
json-array      = begin-array [ json-value *( value-separator json-value ) ] end-array
begin-array     = ws %x5B ws  ; [ left square bracket
end-array       = ws %x5D ws  ; ] right square bracket
value-separator = ws %x2C ws  ; , comma
; JSON objects
json-object    = begin-object [ member *( value-separator member ) ] end-object
begin-object   = ws %x7B ws  ; { left curly bracket
end-object     = ws %x7D ws  ; } right curly bracket
member         = json-string name-separator json-value
name-separator = ws %x3A ws  ; : colon
; JSON numbers
json-number   = [ minus ] int [ frac ] [ exp ]
decimal-point = %x2E                 ; .
digit1-9      = %x31-39              ; 1-9
e             = %x65 / %x45          ; e E
exp           = e [ minus / plus ] 1*digit
frac          = decimal-point 1*digit
int           = zero / ( digit1-9 *digit )
minus         = %x2D                 ; -
plus          = %x2B                 ; +
zero          = %x30                 ; 0

expression

expression        = sub-expression / index-expression  / comparator-expression
expression        =/ or-expression / identifier
expression        =/ and-expression / not-expression / paren-expression
expression        =/ multi-select-list / multi-select-hash / literal
expression        =/ function-expression / pipe-expression / raw-string
expression        =/ root-node / current-node
expression        =/ arithmetic-expression
expression        =/ let-expression / variable-ref
  

Sub-expressions

sub-expression    = expression "." ( identifier / multi-select-list / multi-select-hash / function-expression / "*" )
  

A sub-expression is a combination of two expressions separated by the ‘.’ char. A sub-expression is evaluated as follows:

  • Evaluate the expression on the left with the original JSON document.
  • Evaluate the expression on the right with the result of the left expression evaluation.

In pseudocode:

left-evaluation = search(left-expression, original-json-document)
if left-evaluation is `null` then result = `null`
else result = search(right-expression, left-evaluation)

A sub-expression is itself an expression, so there can be multiple levels of sub-expressions: grandparent.parent.child. Examples

Given a JSON document: {"foo": {"bar": "baz"}}, and a jmespath expression: foo.bar, the evaluation process would be:

left-evaluation = search("foo", {"foo": {"bar": "baz"}}) -> {"bar": "baz"}
result = search("bar": {"bar": "baz"}) -> "baz"

The final result in this example is “baz”.

Additional examples:

search(foo.bar, {"foo": {"bar": "value"}}) -> "value"
search(foo."bar", {"foo": {"bar": "value"}}) -> "value"
search(foo.bar, {"foo": {"baz": "value"}}) -> null
search(foo.bar.baz, {"foo": {"bar": {"baz": "value"}}}) -> "value"

Pipe Expressions

pipe-expression   = expression "|" expression
  

A pipe expression combines two expressions, separated by the | character. It is similar to a sub-expression with a few important distinctions:

  1. Any expression can be used on the right hand side. A sub-expression restricts the type of expression that can be used on the right hand side.
  2. A pipe-expression stops projections on the left hand side for propagating to the right hand side. If the left expression creates a projection, it does not apply to the right hand side.
  3. Contrary to a sub-expression, a pipe-expression does not stop evaluation if the left-hand-side evaluates to null.

In pseudocode:

left-evaluation = search(left-expression, original-json-document)
result = search(right-expression, left-evaluation)

For example, given the following data:

{"foo": [{"bar": ["first1", "second1"]}, {"bar": ["first2", "second2"]}]}

The expression foo[*].bar gives the result of:

[
    [
        "first1",
        "second1"
    ],
    [
        "first2",
        "second2"
    ]
]

The first part of the expression, foo[*], creates a projection. At this point, the remaining expression, bar is projected onto each element of the list created from foo[*]. If you project the [0] expression, you will get the first element from each sub list. The expression foo[*].bar[0] will return:

["first1", "first2"]

If you instead wanted only the first sub list, ["first1", "second1"], you can use a pipe-expression:

foo[*].bar[0] -> ["first1", "first2"]
foo[*].bar | [0] -> ["first1", "second1"]

Examples

search(foo | bar, {"foo": {"bar": "baz"}}) -> "baz"
search(foo[*].bar | [0], {
    "foo": [{"bar": ["first1", "second1"]},
            {"bar": ["first2", "second2"]}]}) -> ["first1", "second1"]
search(foo | [0], {"foo": [0, 1, 2]}) -> [0]

Or Expressions

or-expression     = expression "||" expression
  

An or expression will evaluate to either the left expression or the right expression. If the evaluation of the left expression is not false it is used as the return value. If the evaluation of the right expression is not false it is used as the return value. If neither the left or right expression are non-null, then a value of null is returned. A false value corresponds to any of the following conditions:

  • Empty list: []
  • Empty object: {}
  • Empty string: ""
  • False boolean: false
  • Null value: null

A true value corresponds to any value that is not false.

Examples

search(foo || bar, {"foo": "foo-value"}) -> "foo-value"
search(foo || bar, {"bar": "bar-value"}) -> "bar-value"
search(foo || bar, {"foo": "foo-value", "bar": "bar-value"}) -> "foo-value"
search(foo || bar, {"baz": "baz-value"}) -> null
search(foo || bar || baz, {"baz": "baz-value"}) -> "baz-value"
search(override || mylist[-1], {"mylist": ["one", "two"]}) -> "two"
search(override || mylist[-1], {"mylist": ["one", "two"], "override": "yes"}) -> "yes"

And Expressions

and-expression    = expression "&&" expression
  

An and expression will evaluate to either the left expression or the right expression. If the expression on the left hand side is a truth-like value, then the value on the right hand side is returned. Otherwise the result of the expression on the left hand side is returned. This also reduces to the expected truth table:

Truth table for and expressions

LHSRHSResult
TrueTrueTrue
TrueFalseFalse
FalseTrueFalse
FalseFalseFalse

This is the standard truth table for a logical conjunction (AND).

Examples

search(True && False, {"True": true, "False": false}) -> false
search(Number && EmptyList, {"Number": 5, EmptyList: []}) -> []
search(foo[?a == `1` && b == `2`],
       {"foo": [{"a": 1, "b": 2}, {"a": 1, "b": 3}]}) -> [{"a": 1, "b": 2}]

Not Expressions

not-expression    = "!" expression
  

A not-expression negates the result of an expression. If the expression results in a truth-like value, a not-expression will change this value to false. If the expression results in a false-like value, a not-expression will change this value to true.

Examples

search(!True, {"True": true}) -> false
search(!False, {"False": false}) -> true
search(!Number, {"Number": 5}) -> false
search(!EmptyList, {"EmptyList": []}) -> true

Arithmetic Expressions

arithmetic-expression =/ "+" expression ; + %x43
arithmetic-expression =/ ( "-" / "–" ) expression ; - %x45 – %x2212 \
arithmetic-expression = expression "%" expression ; % %x37 \
arithmetic-expression =/ expression ( "*" / "×" ) expression ; * %x42 ×  %xD7 \
arithmetic-expression =/ expression "+" expression ; + %x43 \
arithmetic-expression =/ expression ( "-" / "–" ) expression ; - %x45 – %x2212 \
arithmetic-expression =/ expression ( "/" / "÷" ) expression ; / %x47 ÷ %F7 \
arithmetic-expression = expression "//" expression ; // %47 %47
  

An arithmetic-expression enables simple computations using the four basic operations, as well as the modulo and integer-division operations.

To support arithmetic operations, the following operators are available:

  • + addition operator
  • - subtraction operator
  • * multiplication operator
  • / division operator
  • % modulo operator
  • // integer division operator

Proper mathematical operators are also supported using the following UNICODE characters:

  • (U+2212 MINUS SIGN)
  • ÷ (U+00F7 DIVISION SIGN)
  • × (U+00D7 MULTIPLY SIGN)

Arithmetic operations adhere to the usual precedence rules, from lowest to highest:

  • - subtraction operator and + addition operator
  • / division, * multiplication, % modulo and // integer division operators

In the absence of parentheses, operators of the same level of precedence are evaluated from left to right. Arithmetic operators have higher precedence than comparison operators and lower precedence than the . “dot” sub-expression token separator.

Examples

search(a + b, {"a": 1, "b": 2}) -> 3
search(a - b, {"a": 1, "b": 2}) -> -1
search(a * b, {"a": 2, "b": 4}) -> 8
search(a / b, {"a": 2, "b": 3}) -> 0.666666666666667
search(a % b, {"a": 10, "b": 3} -> 1
search(a // b, {"a": 10, "b": 3} -> -3
search(a.b + cd, {"a": {"b": 1}, "c": {"d": 2}}) -> 3

Since arithmetic-expression is not valid on the right-hand-side of a sub-expression, a pipe-expression can be used instead:

search({ab: a.b, cd: c.d} | ab + cd, {"a": {"b": 1}, "c": {"d": 2}}) -> 3

Parenthetical Expressions

paren-expression  = "(" expression ")"
  

A paren-expression allows a user to override the precedence order of an expression, e.g. (a || b) && c.

Examples

search(foo[?(a == `1` || b ==`2`) && c == `5`],
       {"foo": [{"a": 1, "b": 2, "c": 3}, {"a": 3, "b": 4}]}) -> []

Index Expressions

index-expression  = expression bracket-specifier / bracket-specifier
bracket-specifier = "[" (number / slice-expression) "]"
  

An index expression is used to access elements in a list. Indexing is 0 based, the index of 0 refers to the first element of the list. A negative number is a valid index. A negative number indicates that indexing is relative to the end of the list, specifically:

negative-index == (length of array) + negative-index

Given an array of length N, an index of -1 would be equal to a positive index of N - 1, which is the last element of the list. If an index expression refers to an index that is greater than the length of the array, a value of null is returned.

For the grammar rule expression bracket-specifier the expression is first evaluated, and then return value from the expression is given as input to the bracket-specifier.

Using a “*” character within a bracket-specifier is discussed below in the wildcard expressions section.

Flatten Operator

bracket-specifier =/ "[]"
  

When the character sequence [] is provided as a bracket specifier, then a flattening operation occurs on the current result. The flattening operator will merge sublists in the current result into a single list. The flattening operator has the following semantics:

  • Create an empty result list.
  • Iterate over the elements of the current result.
  • If the current element is not a list, add to the end of the result list.
  • If the current element is a list, add each element of the current element to the end of the result list.
  • The result list is now the new current result.

Once the flattening operation has been performed, subsequent operations are projected onto the flattened list with the same semantics as a wildcard expression. Thus the difference between [*] and [] is that [] will first flatten sublists in the current result.

Examples

search([0], ["first", "second", "third"]) -> "first"
search([-1], ["first", "second", "third"]) -> "third"
search([100], ["first", "second", "third"]) -> null
search(foo[0], {"foo": ["first", "second", "third"]) -> "first"
search(foo[100], {"foo": ["first", "second", "third"]) -> null
search(foo[0][0], {"foo": [[0, 1], [1, 2]]}) -> 0

Slices

slice-expression  = [number] ":" [number] [ ":" [number] ]
  

A slice expression allows you to select a subset of an array or a string. A slice has a start, stop, and step value. The general form of a slice is [start:stop:step], but each component is optional and can be omitted.

Given a start, stop, and step value, the sub elements in an array or characters in a string are extracted as follows:

  • The first element in the extracted array or first character in the extracted string is the index denoted by start.
  • The last element in the extracted array or last character in the extracted string is the index denoted by end - 1.
  • The step value determines how many indices to skip after each element is selected from the array or each character is selected from the string. The default step value of 1 will not skip any indices and will return a contiguous subset of the original array or a substring of the original string. A step value greater than 1 will skip indices while extracting elements from an array or characters from a string. For instance, a step value of 2 will skip every other element or character. Negative step values start from the end of the array or string and extract elements or characters in reverse order.

Slice expressions adhere to the following rules:

  • If a negative start position is given, it is calculated as the total length of the array or string plus the given start position.
  • If no start position is given, it is assumed to be 0 if the given step is greater than 0 or the end of the array or string if the given step is less than 0.
  • If a negative stop position is given, it is calculated as the total length of the array or string plus the given stop position.
  • If no stop position is given, it is assumed to be the length of the array or string if the given step is greater than 0 or 0 if the given step is less than 0.
  • If the given step is omitted, it it assumed to be 1.
  • If the given step is 0, an invalid-value error MUST be raised.
  • If the element being sliced is not an array or a string, the result is null.
  • If the element being sliced is an array or string and yields no results, the result MUST be an empty array.

Examples

search([0:4:1], [0, 1, 2, 3]) -> [0, 1, 2, 3]
search([0:4], [0, 1, 2, 3]) -> [0, 1, 2, 3]
search([0:3], [0, 1, 2, 3]) -> [0, 1, 2]
search([:2], [0, 1, 2, 3]) -> [0, 1]
search([::2], [0, 1, 2, 3]) -> [0, 2]
search([::-1], [0, 1, 2, 3]) -> [3, 2, 1, 0]
search([-2:], [0, 1, 2, 3]) -> [2, 3]

Slicing operates on strings exactly as if a string were thought of as an array of characters.

search(foo[0:4], {"foo": "hello, world!"}) -> "hell"
search([::], 'raw-string') -> "raw-string"
search([::2], 'raw-string') -> "rwsrn"
search([::-1], 'raw-string') -> "gnirts-war"

MultiSelect List

multi-select-list = "[" ( expression *( "," expression ) ) "]"
  

A multiselect expression is used to extract a subset of elements from a JSON hash. There are two version of multiselect, one in which the multiselect expression is enclosed in {...} and one which is enclosed in [...]. This section describes the [...] version. Within the start and closing characters is one or more non expressions separated by a comma. Each expression will be evaluated against the JSON document. Each returned element will be the result of evaluating the expression. A multi-select-list with N expressions will result in a list of length N. Given a multiselect expression [expr-1,expr-2,...,expr-n], the evaluated expression will return [evaluate(expr-1), evaluate(expr-2), ..., evaluate(expr-n)].

Examples

search([foo,bar], {"foo": "a", "bar": "b", "baz": "c"}) -> ["a", "b"]
search([foo,bar[0]], {"foo": "a", "bar": ["b"], "baz": "c"}) -> ["a", "b"]
search([foo,bar.baz], {"foo": "a", "bar": {"baz": "b"}}) -> ["a", "b"]
search([foo,baz], {"foo": "a", "bar": "b"}) -> ["a", null]

MultiSelect Hash

multi-select-hash = "{" ( keyval-expr *( "," keyval-expr ) ) "}"
keyval-expr       = identifier ":" expression
  

A multi-select-hash expression is similar to a multi-select-list expression, except that a hash is created instead of a list. A multi-select-hash expression also requires key names to be provided, as specified in the keyval-expr rule. Given the following rule:

keyval-expr       = identifier ":" expression

The identifier is used as the key name and the result of evaluating the expression is the value associated with the identifier key.

Each keyval-expr within the multi-select-hash will correspond to a single key value pair in the created hash.

Examples

Given a multi-select-hash expression {foo: one.two, bar: bar} and the data {"bar": "bar", {"one": {"two": "one-two"}}}, the expression is evaluated as follows:

  • A hash is created: {}
  • A key foo is created whose value is the result of evaluating one.two against the provided JSON document: {"foo": evaluate(one.two, <data>)}
  • A key bar is created whose value is the result of evaluting the expression bar against the provided JSON document.

The final result will be: {"foo": "one-two", "bar": "bar"}.

Additional examples:

search({foo: foo, bar: bar}, {"foo": "a", "bar": "b", "baz": "c"})
              -> {"foo": "a", "bar": "b"}
search({foo: foo, firstbar: bar[0]}, {"foo": "a", "bar": ["b"]})
              -> {"foo": "a", "firstbar": "b"}
search({foo: foo, "bar.baz": bar.baz}, {"foo": "a", "bar": {"baz": "b"}})
              -> {"foo": "a", "bar.baz": "b"}
search({foo: foo, baz: baz}, {"foo": "a", "bar": "b"})
              -> {"foo": "a", "baz": null}

Wildcard Expressions

expression        =/ "*"
bracket-specifier =/ "[" "*" "]"
  

A wildcard expression is a expression of either * or [*]. A wildcard expression can return multiple elements, and the remaining expressions are evaluated against each returned element from a wildcard expression. The [*] syntax applies to a list type and the *syntax applies to a hash type.

The [*] syntax (referred to as a list wildcard expression) will return all the elements in a list. Any subsequent expressions will be evaluated against each individual element. Given an expression [*].child-expr, and a list of N elements, the evaluation of this expression would be [child-expr(el-0), child-expr(el-2), ..., child-expr(el-N)]. This is referred to as a projection, and the child-expr expression is projected onto the elements of the resulting list.

Once a projection has been created, all subsequent expressions are projected onto the resulting list.

The * syntax (referred to as a hash wildcard expression) will return a list of the hash element’s values. Any subsequent expression will be evaluated against each individual element in the list (this is also referred to as a projection).

Note that if any subsequent expression after a wildcard expression returns a null value, it is omitted from the final result list.

A list wildcard expression is only valid for the JSON array type. If a list wildcard expression is applied to any other JSON type, a value of null is returned.

Similarly, a hash wildcard expression is only valid for the JSON object type. If a hash wildcard expression is applied to any other JSON type, a value of null is returned. Note that JSON hashes are explicitly defined as unordered. Therefore a hash wildcard expression can return the values associated with the hash in any order. Implementations are not required to return the hash values in any specific order.

Examples

search([*].foo, [{"foo": 1}, {"foo": 2}, {"foo": 3}]) -> [1, 2, 3]
search([*].foo, [{"foo": 1}, {"foo": 2}, {"bar": 3}]) -> [1, 2]
search('*.foo', {"a": {"foo": 1}, "b": {"foo": 2}, "c": {"bar": 1}}) -> [1, 2]

Filter Expressions

filter-expression = "[?" expression "]"
bracket-specifier =/ filter-expression
comparator-expression = expression comparator expression
comparator        = "<" / "<=" / "==" / ">=" / ">" / "!="
  

A filter expression provides a way to select JSON elements based on a comparison to another expression. A filter expression is evaluated as follows: for each element in an array evaluate the expression against the element. If the expression evaluates to a truth-like value, the item (in its entirety) is added to the result list. Otherwise it is excluded from the result list. A filter expression is only defined for a JSON array. Attempting to evaluate a filter expression against any other type will return null.

Comparison Operators

The following operations are supported:

  • ==, tests for equality.
  • !=, tests for inequality.
  • <, less than.
  • <=, less than or equal to.
  • , greater than.

  • =, greater than or equal to.

The behavior of each operation is dependent on the type of each evaluated expression.

The comparison semantics for each operator are defined below based on the corresponding JSON type:

Equality Operators

For string/number/true/false/null types, equality is an exact match. A string is equal to another string if they they have the exact sequence of code points. The literal values true/false/null are only equal to their own literal values. Two JSON objects are equal if they have the same set of keys and values (given two JSON objects x and y, for each key value pair (i, j) in x, there exists an equivalent pair (i, j) in y). Two JSON arrays are equal if they have equal elements in the same order (given two arrays x and y, for each i from 0 until length(x), x[i] == y[i]).

Ordering Operators

Ordering operators >, >=, <, <= are only valid for numbers. Evaluating any other type with a comparison operator will yield a null value, which will result in the element being excluded from the result list. For example, given:

search('foo[?a<b]', {"foo": [{"a": "char", "b": "char"},
                             {"a": 2, "b": 1},
                             {"a": 1, "b": 2}]})

The three elements in the foo list are evaluated against a < b. The first element resolves to the comparison “char” < “bar”, and because these types are string, the expression results in null, so the first element is not included in the result list. The second element resolves to 2 < 1, which is false, so the second element is excluded from the result list. The third expression resolves to 1 < 2 which evaluates to true, so the third element is included in the list. The final result of that expression is [{"a": 1, "b": 2}].

Examples

search(foo[?bar==`10`], {"foo": [{"bar": 1}, {"bar": 10}]}) -> [{"bar": 10}]
search([?bar==`10`], [{"bar": 1}, {"bar": 10}]}) -> [{"bar": 10}]
search(foo[?a==b], {"foo": [{"a": 1, "b": 2}, {"a": 2, "b": 2}]}) -> [{"a": 2, "b": 2}]

Function Expressions

function-expression = unquoted-string  ( no-args  / one-or-more-args )
no-args             = "(" ")"
one-or-more-args    = "(" ( function-arg *( "," function-arg ) ) ")"
function-arg        = expression / expression-type
current-node        = "@"
root-node           = "$"
expression-type     = "&" expression
  

Functions allow users to easily transform and filter data in JMESPath expressions.

Data Types

In order to support functions, a type system is needed. The JSON types are used:

  • number (integers and double-precision floating-point format in JSON)
  • string (a sequence of Unicode code points . Note that a code point is distinct to a code unit )
  • boolean (true or false)
  • array (an ordered, sequence of values)
  • object (an unordered collection of key value pairs)
  • null

There is also an additional type that is not a JSON type that’s used in JMESPath functions:

  • expression (denoted by &expression)

current-node

The current-node token can be used to represent the current node being evaluated. The current-node token is useful for functions that require the current node being evaluated as an argument. For example, the following expression creates an array containing the total number of elements in the foo object followed by the value of foo["bar"].

foo[].[count(@), bar]

JMESPath assumes that all function arguments operate on the current node unless the argument is a literal or number token. Because of this, an expression such as @.bar would be equivalent to just bar, so the current node is only allowed as a bare expression.

current-node state

At the start of an expression, the value of the current node is the data being evaluated by the JMESPath expression. As an expression is evaluated, the value the the current node represents MUST change to reflect the node currently being evaluated. When in a projection, the current node value must be changed to the node currently being evaluated by the projection.

root-node

The root-node token can be used to represent the original input JSON document.

As a JMESPath expression is being evaluated, the current scope changes. Given a simple sub expression such as foo.bar, first the foo expression is evaluated with the starting input JSON document, and the result of that expression is then used as the current scope when the bar element is evaluated.

Once we’ve drilled down to a specific scope, the root-node token can be used to refer to the original JSON document.

Example

Given a JSON document:

{
  "first_choice": "WA",
  "states": [
     {"name": "WA", "cities": ["Seattle", "Bellevue", "Olympia"]},
     {"name": "CA", "cities": ["Los Angeles", "San Francisco"]},
     {"name": "NY", "cities": ["New York City", "Albany"]}
 ]
}

We can retrieve the list of cities of the state corresponding to the first_choice key using the following expression:

states[? name == $.first_choice ].cities[]

Let Expressions

let-expression = "let" bindings "in" expression
bindings = variable-binding *( "," variable-binding ) \
variable-binding = variable-ref "=" expression \
variable-ref = "$" unquoted-string
  

A let-expression introduces lexical scoping and lets you bind variables that are evaluated In the context of a given lexical scope. This enables queries that can refer to elements defined outside of their current element

Examples of this new syntax:

  • let $foo = bar in {a: myvar, b: $foo}
  • let $foo = baz[0] in bar[? baz == $foo ] | [0]
  • let $a = b, $c = d in bar[*].[$a, $c, foo, bar]

Function Evaluation

Functions are evaluated in applicative order. Each argument must be an expression, each argument expression must be evaluated before evaluating the function. The function is then called with the evaluated function arguments. The result of the function-expression is the result returned by the function call. If a function-expression is evaluated for a function that does not exist, the JMESPath implementation must indicate to the caller that an unknown-function error occurred. How and when this error is raised is implementation specific, but implementations should indicate to the caller that this specific error occurred.

Functions can have a specific arity, a range of valid – minimum and maximum – number of arguments or be variadic with a minimum number of arguments. If a function-expression is encountered where the arity does not match or the minimum number of arguments for a variadic function is not provided, then implementations must indicate to the caller that an invalid-arity error occurred. How and when this error is raised is implementation specific.

Each function signature declares the types of its input parameters. If any type constraints are not met, implementations must indicate that an invalid-type error occurred.

In order to accommodate type constraints, functions are provided to convert types to other types (to_string, to_number) which are defined below. No explicit type conversion happens unless a user specifically uses one of these type conversion functions.

Function expressions are also allowed as the child element of a sub expression. This allows functions to be used with projections, which can enable functions to be applied to every element in a projection. For example, given the input data of ["1", "2", "3", "notanumber", true], the following expression can be used to convert (and filter) all elements to numbers:

search([].to_number(@), ``["1", "2", "3", "notanumber", true]``) -> [1, 2, 3]

This provides a simple mechanism to explicitly convert types when needed.

Raw String Literals

raw-string        = "'" *raw-string-char "'"
raw-string-char   = (%x00-26 / %x28-5B / %x5D-10FFFF) / preserved-escape / raw-string-escape
preserved-escape  = escape (%x00-26 / %x28-5B / %x5D-10FFFF)
raw-string-escape = escape ("'" / escape)
  

A raw string is an expression that allows for a literal string value to be specified. The result of evaluating the raw string literal expression is the literal string value. It is a simpler form of a literal expression that is special cased for strings. For example, the following expressions both evaluate to the same value: “foo”:

search(`"foo"`, "") -> "foo"
search('foo', "") -> "foo"

As you can see in the examples above, it is meant as a more succinct form of the common scenario of specifying a literal string value.

In addition, it does not perform any of the additional processing that JSON strings supports including:

  • Not expanding unicode escape sequences
  • Not expanding newline characters
  • Not expanding tab characters or any other escape sequences documented in RFC 4627 section 2.5.

Examples

search('foo', "") -> "foo"
search(' bar ', "") -> " bar "
search('[baz]', "") -> "[baz]"
search('\u03bB', "") -> "\\u03bB"
search('foo␊bar', "") -> "foo\nbar"
search('foo\␊bar', "") -> "foo\\\nbar"
search('\\', "") -> "\\"

Literal Expressions

literal           = "`" json-text "`"
  

A literal expression is an expression that allows arbitrary JSON objects to be specified. This is useful in filter expressions as well as multi select hashes (to create arbitrary key value pairs), but is allowed anywhere an expression is allowed. The specification includes the ABNF for JSON, implementations should use an existing JSON parser to parse literal values. Note that the ` character must now be escaped in a json-value which means implementations need to handle this case before passing the resulting string to a JSON parser.

Examples

search(`"foo"`, "anything") -> "foo"
search(`"foo\`bar"`, "anything") -> "foo`bar"
search(`[1, 2]`, "anything") -> [1, 2]
search(`true`, "anything") -> true
search(`{"a": "b"}`.a, "anything") -> "b"
search({first: a, type: `"mytype"`}, {"a": "b", "c": "d"}) -> {"first": "b", "type": "mytype"}

Identifiers

identifier        = unquoted-string / quoted-string
  

An identifier is the most basic expression and can be used to extract a single element from a JSON document. The return value for an identifier is the value associated with the identifier. If the identifier does not exist in the JSON document, than a null value is returned. From the grammar rule listed above identifiers can be one or more characters, and must start with A-Za-z_. An identifier can also be quoted. This is necessary when an identifier has characters not specified in the unquoted-string grammar rule. In this situation, an identifier is specified with a double quote, followed by any number of unescaped-char or escaped-char characters, followed by a double quote. The quoted-string rule is the same grammar rule as a JSON string, so any valid string can be used between double quoted, include JSON supported escape sequences, and six character unicode escape sequences. Note that any identifier that does not start with A-Za-z_ must be quoted.

Examples:

search(foo, {"foo": "value"}) -> "value"
search(bar, {"foo": "value"}) -> null
search(foo, {"foo": [0, 1, 2]}) -> [0, 1, 2]
search("with space", {"with space": "value"}) -> "value"
search("special chars: !@#", {"special chars: !@#": "value"}) -> "value"
search("quote\"char", {"quote\"char": "value"}) -> "value"
search("\u2713", {"\u2713": "value"}) -> "value"

Built-in Functions

abs
number abs number $value
Arguments
NamePresenceTypeDescription
$valuerequirednumberpositive or negative number
Returnsnumberpositive magnitude of input value

Returns the absolute value of the provided argument. The signature indicates that a number is returned, and that the input argument $value must resolve to a number, otherwise an invalid-type error is triggered.

Below is a worked example. Given:

{"foo": -1, "bar": "2"}

Evaluating abs(foo) works as follows:

  1. Evaluate the input argument against the current data:
search(foo, {"foo": -1, "bar": "2"}) -> -1
  1. Validate the type of the resolved argument. In this case -1 is of type number so it passes the type check.

  2. Call the function with the resolved argument:

abs(-1) -> 1
  1. The value of 1 is the resolved value of the function expression abs(foo).

Below is the same steps for evaluating abs(bar):

  1. Evaluate the input argument against the current data:
search(bar, {"foo": -1, "bar": "2"}) -> "2"
  1. Validate the type of the resolved argument. In this case "2" is of type string so we immediately indicate that an invalid-type error occurred.

As a final example, here is the steps for evaluating abs(to_number(bar)):

  1. Evaluate the input argument against the current data:
search(to_number(bar), {"foo": -1, "bar": "2"})
  1. In order to evaluate the above expression, we need to evaluate to_number(bar):
search(bar, {"foo": -1, "bar": "2"}) -> "2"
# Validate "2" passes the type check for to_number, which it does.
to_number("2") -> 2

Note that to_number is defined below.

  1. Now we can evaluate the original expression:
search(to_number(bar), {"foo": -1, "bar": "2"}) -> 2
  1. Call the function with the final resolved value:
abs(2) -> 2
  1. The value of 2 is the resolved value of the function expression abs(to_number(bar)).
Examples
GivenExpressionResult
nullabs(1)1
nullabs(abc)null
nullabs(-1)1
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}abs(str)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}abs(array[1])3
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}abs()null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}abs(foo)1
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}abs(-24)24
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}abs(false)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}abs(1, 2)null
avg
number|null avg array[number] $elements
Arguments
NamePresenceTypeDescription
$elementsrequiredarray[number]array of numbers to calculate average from
Returnsnumber|nullaverage value of passed elements

Returns the average of the elements in the provided array.

An empty array will produce a return value of null.

Examples
GivenExpressionResult
falseavg(@)null
[false]avg(@)null
[10,15,20]avg(@)15
[10,false,20]avg(@)null
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}avg(@)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}avg(empty_list)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}avg(array)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}avg(abc)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}avg(foo)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}avg(numbers)2.75
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}avg(strings)null
ceil
number ceil number $value
Arguments
NamePresenceTypeDescription
$valuerequirednumber
Returnsnumber
Returns the next highest integer value by rounding up if necessary.
Examples
GivenExpressionResult
nullceil(1.9)2
nullceil(1)1
nullceil(abc)null
nullceil(1.001)2
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}ceil(decimals[2])-1
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}ceil(1.2)2
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}ceil(decimals[0])2
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}ceil('string')null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}ceil(decimals[1])2
contains
boolean contains array|string $subjectany $search
Arguments
NamePresenceTypeDescription
$subjectrequiredarray|string
$searchrequiredany
Returnsboolean

Returns true if the given $subject contains the provided $search value.

If $subject is an array, this function returns true if one of the elements in the array is equal to the provided $search value.

If the provided $subject is a string, this function returns true if there exists within the $subject string at least one occurrence of an equal $search string. If the $search value is not a string, the function MUST return false.

Examples
GivenExpressionResult
nullcontains(false, 'bar')null
nullcontains('foobar', 'foo')true
nullcontains('foobar', 'bar')true
nullcontains('foobar', 'not')false
nullcontains('foobar', '123')false
["a"]contains(@, 'a')true
["a"]contains(@, 'b')false
["foo","bar"]contains(@, 'b')false
["foo","bar"]contains(@, 'foo')true
["a","b"]contains(@, 'a')true
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}contains('abc', 'a')true
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}contains('abc', 'd')false
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}contains(decimals, false)false
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}contains(decimals, 1.2)true
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}contains(strings, 'a')true
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}contains(false, 'd')null
ends_with
boolean ends_with string $subjectstring $prefix
Arguments
NamePresenceTypeDescription
$subjectrequiredstring
$prefixrequiredstring
Returnsboolean
Returns true if the $subject ends with the $prefix, otherwise this function returns false.
Examples
GivenExpressionResult
"foobarbaz"ends_with(@, 'z')true
"foobarbaz"ends_with(@, 'baz')true
"foobarbaz"ends_with(@, 'foo')false
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}ends_with(str, 'tr')true
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}ends_with(str, 'Str')true
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}ends_with(str, 0)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}ends_with(str, 'r')true
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}ends_with(str, 'foo')false
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}ends_with(str, 'SStr')false
find_first
number find_first string $subjectstring $subnumber $start number $end
Arguments
NamePresenceTypeDescription
$subjectrequiredstringSubject string
$subrequiredstringSubstring
$startoptionalnumberPosition in the subject string where searching should start.
$endoptionalnumberPosition in the subject string where searching should end.
Returnsnumber

Given the subject string, find_first() returns the zero-based index of the first occurence where the sub substring appears in subject or null if it does not appear. If either the $subject or the $sub argument is an empty string, find_first() return null.

The start and end parameters are optional and allow restricting the range within subject in which sub must be found.

  • If start is omitted, it defaults to 0 (which is the start of the subject string).
  • If end is omitted, it defaults to length(subject) - 1 (which is is the end of the subject string).

If not omitted, the $start and $end arguments are expected to be integers. Othewise, an error MUST be raised.

Contrary to similar functions found in most popular programming languages, the find_first() function does not return -1 if no occurrence of the substring can be found. Instead, it returns null for consistency reasons with how JMESPath behaves.

Examples
GivenExpressionResult
"subject string"find_first(@, string, `0`)8
"subject string"find_first(@, s, `0`)0
"subject string"find_first(@, s, `1`)8
"subject string"find_first(@, string)8
"subject string"find_first(@, string, `0`, `14`)8
"subject string"find_first(@, string, `0`, `13`)null
"subject string"find_first(@, string, `9`)null
"subject string"find_first(@, string, `-99`, `100`)8
"subject string"find_first(@, string, `8`)8
find_last
number find_last string $subjectstring $subnumber $start number $end
Arguments
NamePresenceTypeDescription
$subjectrequiredstringSubject string
$subrequiredstringSubstring
$startoptionalnumberPosition in the subject string where searching should start.
$endoptionalnumberPosition in the subject string where searching should end.
Returnsnumber

Given the $subject string, find_last() returns the zero-based index of the last occurence where the $sub substring appears in $subject or null if it does not appear. If either the $subject or the $sub argument is an empty string, find_last() returns null.

The $start and $end parameters are optional and allow restricting to the slice [$start:$end] the range within $subject in which $sub must be found.

  • If $start is omitted, it defaults to 0 (which is the start of the $subject string).
  • If $end is omitted, it defaults to length(subject) (which is past the end of the $subject string).

If not omitted, the $start or $end arguments are expected to be integers. Otherwise, an error MUST be raised.

Contrary to similar functions found in most popular programming languages, the find_last() function does not return -1 if no occurrence of the substring can be found. Instead, it returns null for consistency reasons with how JMESPath behaves.

Examples
GivenExpressionResult
"subject string"find_last(@, string)8
"subject string"find_last(@, string, `8`)8
"subject string"find_last(@, string, `8`, `9`)null
"subject string"find_last(@, string, `9`)null
"subject string"find_last(@, s, `1`)8
"subject string"find_last(@, s, `0`, `7`)0
floor
number floor number $value
Arguments
NamePresenceTypeDescription
$valuerequirednumber
Returnsnumber
Returns the next lowest integer value by rounding down if necessary.
Examples
GivenExpressionResult
nullfloor(1.001)1
nullfloor(1.9)1
nullfloor(1)1
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}floor(foo)-1
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}floor(str)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}floor(1.2)1
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}floor(string)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}floor(decimals[0])1
from_items
object from_items array[any] $arg
Arguments
NamePresenceTypeDescription
$argrequiredarray[any]
Returnsobject
Returns an object from the provided array of key value pairs. This function is the inversed of the items() function.
Examples
GivenExpressionResult
[["one",1],["two",2]]from_items(@){"one":1,"two":2}
[["one",1],["two",2],["one",3]]from_items(@){"one":3,"two":2}
group_by
object group_by array[object] $elementsexpression->string $expr
Arguments
NamePresenceTypeDescription
$elementsrequiredarray[object]
$exprrequiredexpression->string
Returnsobject

Groups an array of objects $elements using an expression $expr as the group key. The $expr expression is applied to each element in the array $elements and the resulting value is used as a group key.

The result is an object whose keys are the unique set of string keys and whose respective values are an array of objects array matching the group criteria.

Objects that do not match the group criteria are discarded from the output. This includes objects for which applying the $expr expression evaluates to null.

If the result of applying the $expr expression against the current array element results in type other than string or null, an invalid-type error MUST be raised.

Examples
GivenExpressionResult
Show more..
{"items":[{"spec":{"nodeName":"node_01","other":"values_01"}},{"spec":{"nodeName":"node_02","other":"values_02"}},{"spec":{"nodeName":"node_03","other":"values_03"}},{"spec":{"nodeName":"node_01","other":"values_04"}}]}group_by(items, &nodeName){"nodeName":{"node_01":[{"spec":{"nodeName":"node_01","other":"values_01"}},{"spec":{"nodeName":"node_01","other":"values_04"}}],"node_02":[{"spec":{"nodeName":"node_02","other":"values_02"}}],"node_03":[{"spec":{"nodeName":"node_03","other":"values_03"}}]}}
{"array":[{"b":true,"name":"one"},{"b":false,"name":"two"},{"b":false}]}group_by(array, &name)[{"age":10,"age_str":"10","bool":true,"name":3},{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":50,"age_str":"50","bool":false,"name":"d"}]
{"array":[{"b":true,"name":"one"},{"b":false,"name":"two"},{"b":false}]}group_by(array, &b)null
items
array[any] items object $obj
Arguments
NamePresenceTypeDescription
$objrequiredobject
Returnsarray[any]

Returns an array of key-value pairs for the provided input object. Each pair is a 2-item array with the first item being the key and the second item being the value. This function is the inversed of the from_items() function.

Note that because JSON hashes are inheritently unordered, the key value pairs of the provided object $obj are inheritently unordered. Implementations are not required to return values in any specific order.

Examples
GivenExpressionResult
{"a":"first","b":"second"}items(@)[["a","first"],["b","second"]]
join
string join string $gluearray[string] $stringsarray
Arguments
NamePresenceTypeDescription
$gluerequiredstring
$stringsarrayrequiredarray[string]
Returnsstring
Returns all of the elements from the provided $stringsarray array joined together using the $glue argument as a separator between each.
Examples
GivenExpressionResult
[false]join(', ', @)null
["a","b"]join(', ', @)"a, b"
["a","b"]join('', @)"ab"
["a",false,"b"]join(', ', @)null
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}join('|', decimals[].to_string(@))"1.01|1.2|-1.5"
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}join(', ', )"a, b"
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}join('|', strings)"a|b|c"
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}join(', ', str)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}join('|', decimals)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}join(', ', strings)"a, b, c"
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}join('|', empty_list)""
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}join(', ', )null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}join(2, strings)null
keys
array keys object $obj
Arguments
NamePresenceTypeDescription
$objrequiredobject
Returnsarray
Returns an array containing the keys of the provided object. Note that because JSON hashes are inheritently unordered, the keys associated with the provided object obj are inheritently unordered. Implementations are not required to return keys in any specific order.
Examples
GivenExpressionResult
{}keys(@)[]
falsekeys(@)null
{"bar":"bam","foo":"baz"}keys(@)["foo","bar"]
["b","a","c"]keys(@)null
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}keys(foo)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}keys(strings)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}keys(false)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}keys(empty_hash)[]
length
number length string|array|object $subject
Arguments
NamePresenceTypeDescription
$subjectrequiredstring|array|object
Returnsnumber

Returns the length of the given argument using the following types rules:

  1. string: returns the number of code points in the string

  2. array: returns the number of elements in the array

  3. object: returns the number of key-value pairs in the object

Examples
GivenExpressionResult
nulllength(not_there)null
[]length(@)0
nulllength('abc')3
{}length(@)0
{"baz":"bam","foo":"bar"}length(@)2
["a","b","c"]length(@)3
[1,2,3,4,5,6,7]length(@)7
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}length('abc')3
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}length('')0
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}length(str)3
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}length(strings[0])1
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}length(objects)2
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}length(false)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}length(@)12
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}length('✓foo')4
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}length(foo)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}length(array)6
lower
string lower string $subject
Arguments
NamePresenceTypeDescription
$subjectrequiredstringSubject string
Returnsstring
Returns the lowercase subject string.
Examples
GivenExpressionResult
"STRING"lower(@)"string"
map
array[any] map expression $exprarray[any] $elements
Arguments
NamePresenceTypeDescription
$exprrequiredexpression
$elementsrequiredarray[any]
Returnsarray[any]

Apply the expr to every element in the elements array and return the array of results. An elements of length N will produce a return array of length N.

Unlike a projection, ([\*].bar), map() will include the result of applying the expr for every element in the elements array, even if the result if null.

Examples
GivenExpressionResult
Show more..
{"array":[{"foo":{"bar":"yes1"}},{"foo":{"bar":"yes2"}},{"foo1":{"bar":false}}]}map(&foo.bar.baz, array)[null,null,null]
{"array":[[1,2,3,[4]],[5,6,7,[8,9]]]}map(&[], array)[[1,2,3,4],[5,6,7,8,9]]
{"array":[{"foo":{"bar":"yes1"}},{"foo":{"bar":"yes2"}},{"foo1":{"bar":false}}]}map(&foo.bar, array)["yes1","yes2",null]
{"array":[{"foo":{"bar":"yes1"}},{"foo":{"bar":"yes2"}},{"foo1":{"bar":false}}]}map(&foo1.bar, array)[null,null,false]
{"array":[{"foo":"a"},{"foo":"b"},{},[],{"foo":"f"}]}map(&foo, array)["a","b",null,null,"f"]
{"empty":[],"people":[{"a":10,"b":1,"c":"z"},{"a":10,"b":2,"c":null},{"a":10,"b":3},{"a":10,"b":4,"c":"z"},{"a":10,"b":5,"c":null},{"a":10,"b":6},{"a":10,"b":7,"c":"z"},{"a":10,"b":8,"c":null},{"a":10,"b":9}]}map(&a, badkey)null
[[1,2,3,[4]],[5,6,7,[8,9]]]map(&[], @)[[1,2,3,4],[5,6,7,8,9]]
{"empty":[],"people":[{"a":10,"b":1,"c":"z"},{"a":10,"b":2,"c":null},{"a":10,"b":3},{"a":10,"b":4,"c":"z"},{"a":10,"b":5,"c":null},{"a":10,"b":6},{"a":10,"b":7,"c":"z"},{"a":10,"b":8,"c":null},{"a":10,"b":9}]}map(&a, people)[10,10,10,10,10,10,10,10,10]
{"empty":[],"people":[{"a":10,"b":1,"c":"z"},{"a":10,"b":2,"c":null},{"a":10,"b":3},{"a":10,"b":4,"c":"z"},{"a":10,"b":5,"c":null},{"a":10,"b":6},{"a":10,"b":7,"c":"z"},{"a":10,"b":8,"c":null},{"a":10,"b":9}]}map(&foo, empty)[]
{"empty":[],"people":[{"a":10,"b":1,"c":"z"},{"a":10,"b":2,"c":null},{"a":10,"b":3},{"a":10,"b":4,"c":"z"},{"a":10,"b":5,"c":null},{"a":10,"b":6},{"a":10,"b":7,"c":"z"},{"a":10,"b":8,"c":null},{"a":10,"b":9}]}map(&c, people)["z",null,null,"z",null,null,"z",null,null]
max
number max array[number]|array[string] $collection
Arguments
NamePresenceTypeDescription
$collectionrequiredarray[number]|array[string]
Returnsnumber

Returns the highest found number in the provided array argument.

An empty array will produce a return value of null.

Examples
GivenExpressionResult
[10,15]max(@)15
["a","b"]max(@)"b"
["a",2,"b"]max(@)null
[10,false,20]max(@)null
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}max(strings)"c"
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}max(empty_list)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}max(decimals)1.2
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}max(numbers)5
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}max(abc)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}max(array)null
max_by
any max_by array $elementsexpression->number|expression->string $expr
Arguments
NamePresenceTypeDescription
$elementsrequiredarray
$exprrequiredexpression->number|expression->string
Returnsany
Return the maximum element in an array using the expression expr as the comparison key. The entire maximum element is returned. Below are several examples using the people array (defined above) as the given input.
Examples
GivenExpressionResult
Show more..
{"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}max_by(people, &to_number(age_str)){"age":50,"age_str":"50","bool":false,"name":"d"}
{"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}max_by(people, &age_str)null
{"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}max_by(people, age)null
{"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}max_by(people, &age){"age":50,"age_str":"50","bool":false,"name":"d"}
{"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}max_by(people, &age_str){"age":50,"age_str":"50","bool":false,"name":"d"}
{"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}max_by(people, &bool)null
{"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}max_by(people, &extra)null
merge
object merge object $argumentobject $..
Arguments
NamePresenceTypeDescription
$argumentrequiredobject
$..optionalobject
Returnsobject
Accepts 0 or more objects as arguments, and returns a single object with subsequent objects merged. Each subsequent object’s key/value pairs are added to the preceding object. This function is used to combine multiple objects into one. You can think of this as the first object being the base object, and each subsequent argument being overrides that are applied to the base object.
Examples
GivenExpressionResult
nullmerge(){"a":"b","c":"d"}
nullmerge(){"a":"override"}
nullmerge(){"a":"x","b":"override","c":"z"}
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}merge(){"a":1,"b":2}
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}merge(){"a":2}
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}merge(){"a":2,"b":2,"c":3,"d":4}
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}merge(empty_hash){}
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}merge(empty_hash, empty_hash){}
min
number min array[number]|array[string] $collection
Arguments
NamePresenceTypeDescription
$collectionrequiredarray[number]|array[string]
Returnsnumber
Returns the lowest found number in the provided $collection argument.
Examples
GivenExpressionResult
["a","b"]min(@)"a"
[10,15]min(@)10
["a",2,"b"]min(@)null
[10,false,20]min(@)null
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}min(decimals)-1.5
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}min(abc)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}min(empty_list)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}min(strings)"a"
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}min(numbers)-1
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}min(array)null
min_by
any min_by array $elementsexpression->number|expression->string $expr
Arguments
NamePresenceTypeDescription
$elementsrequiredarray
$exprrequiredexpression->number|expression->string
Returnsany
Return the minimum element in an array using the expression expr as the comparison key. The entire maximum element is returned. Below are several examples using the people array (defined above) as the given input.
Examples
GivenExpressionResult
Show more..
{"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}min_by(people, &to_number(age_str)){"age":10,"age_str":"10","bool":true,"name":3}
{"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}min_by(people, &age_str)null
{"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}min_by(people, age)null
{"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}min_by(people, &age){"age":10,"age_str":"10","bool":true,"name":3}
{"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}min_by(people, &age_str){"age":10,"age_str":"10","bool":true,"name":3}
{"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}min_by(people, &bool)null
{"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}min_by(people, &extra)null
not_null
any not_null any $argumentany $..
Arguments
NamePresenceTypeDescription
$argumentrequiredany
$..optionalany
Returnsany
Returns the first argument that does not resolve to null. This function accepts one or more arguments, and will evaluate them in order until a non null argument is encounted. If all arguments values resolve to null, then a value of null is returned.
Examples
GivenExpressionResult
{"a":null,"b":null,"c":[],"d":"foo"}not_null(a, b, , d, c)"foo"
{"a":null,"b":null,"c":[],"d":"foo"}not_null(a, b)null
{"a":null,"b":null,"c":[],"d":"foo"}not_null(no_exist, a, b, c, d)[]
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}not_null(unknown_key, str)"Str"
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}not_null(unknown_key, foo.bar, empty_list, str)[]
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}not_null(unknown_key, null_key, empty_list, str)[]
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}not_null(all, expressions, are_null)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}not_null()null
pad_left
string pad_left string $subjectnumber $widthstring $pad
Arguments
NamePresenceTypeDescription
$subjectrequiredstringSubject string
$widthrequirednumberTotal width of the resulting string
$padoptionalstringPad character
Returnsstring

Given the subject string, pad_left() adds characters to the beginning and returns a string of length at least width.

The pad optional string parameter specifies the padding character. If omitted, it defaults to an ASCII space (U+0020). If present, it MUST have length 1, otherwise an error MUST be raised.

If the subject string has length greater than or equal to width, it is returned unmodified.

If $width is not an integer, an error MUST be raised.

Examples
GivenExpressionResult
"string"pad_left(@, `6`)"string"
"string"pad_left(@, `10`)" string"
"string"pad_left(@, `10`, -)"----string"
"string"pad_left(@, `0`)"string"
pad_right
string pad_right string $subjectnumber $widthstring $pad
Arguments
NamePresenceTypeDescription
$subjectrequiredstringSubject string
$widthrequirednumberTotal width of the resulting string
$padoptionalstringPad character
Returnsstring

Given the subject string, pad_right() adds characters to the end and returns a string of length at least width.

The pad optional string parameter specifies the padding character. If omitted, it defaults to an ASCII space (U+0020). If present, it MUST have length 1, otherwise an error MUST be raised.

If the subject string has length greater than or equal to width, it is returned unmodified.

If $width is not an integer, an error MUST be raised.

Examples
GivenExpressionResult
"string"pad_right(@, `10`)"string "
"string"pad_right(@, `10`, -)"string----"
"string"pad_right(@, `0`)"string"
"string"pad_right(@, `6`)"string"
replace
string replace string $subjectstring $oldstring $newnumber $count
Arguments
NamePresenceTypeDescription
$subjectrequiredstringSubject string
$oldrequiredstringText that must be replaced in the subject string
$newrequiredstringText used as a replacement
$countoptionalnumberNumber of replacements to perform
Returnsstring

Given the subject string, replace() replaces ocurrences of the old substring with the new substring.

The count optional parameter specifies how many occurrences of the old substring in subject are to be replaced. If this parameter is omitted, all occurrences are replaced. If count is not an integer or is negative,

The replace() function has no effect if count is 0.

Examples
GivenExpressionResult
"aabaaabaaaab"replace(@, 'aa', '-', `0`)"aabaaabaaaab"
"aabaaabaaaab"replace(@, 'aa', '-', `1`)"-baaabaaaab"
"aabaaabaaaab"replace(@, 'aa', '-', `2`)"-b-abaaaab"
"aabaaabaaaab"replace(@, 'aa', '-', `3`)"-b-ab-aab"
"aabaaabaaaab"replace(@, 'aa', '-')"-b-ab--b"
reverse
array reverse string|array $argument
Arguments
NamePresenceTypeDescription
$argumentrequiredstring|array
Returnsarray
Reverses the order of the $argument.
Examples
GivenExpressionResult
[]reverse(@)[]
"abcd"reverse(@)"dcba"
[0,1,2,3,4]reverse(@)[4,3,2,1,0]
["a","b","c",1,2,3]reverse(@)[3,2,1,"c","b","a"]
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}reverse('')""
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}reverse(empty_list)[]
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}reverse('hello world')"dlrow olleh"
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}reverse(array)["100","a",5,4,3,-1]
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}reverse(numbers)[5,4,3,-1]
sort
array sort array[number]|array[string] $list
Arguments
NamePresenceTypeDescription
$listrequiredarray[number]|array[string]
Returnsarray

This function accepts an array $list argument and returns the sorted elements of the $list as an array.

The array must be a list of strings or numbers. Sorting strings is based on code points. Locale is not taken into account.

Examples
GivenExpressionResult
falsesort(@)null
{"a":1,"b":2}sort(@)null
[1,"a","c"]sort(@)[1,"a","c"]
[[],{},false]sort(@)[{},[],false]
["b","a","c"]sort(@)["a","b","c"]
[false,[],null]sort(@)[[],null,false]
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}sort(values(objects))["bar","baz"]
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}sort(abc)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}sort(keys(objects))["bar","foo"]
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}sort(numbers)[-1,3,4,5]
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}sort(decimals)[-1.5,1.01,1.2]
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}sort(strings)["a","b","c"]
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}sort(empty_list)[]
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}sort(@)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}sort(array)null
sort_by
array sort_by array $elementsexpression->number|expression->string $expr
Arguments
NamePresenceTypeDescription
$elementsrequiredarray
$exprrequiredexpression->number|expression->string
Returnsarray

Sort an array using an expression expr as the sort key. For each element in the array of elements, the expr expression is applied and the resulting value is used as the key used when sorting the elements.

If the result of evaluating the expr against the current array element results in type other than a number or a string, an invalid-type error will occur.

Below are several examples using the people array (defined above) as the given input. sort_by follows the same sorting logic as the sort function.

Examples
GivenExpressionResult
Show more..
{"people":[{"age":10,"order":"1"},{"age":10,"order":"2"},{"age":10,"order":"3"},{"age":10,"order":"4"},{"age":10,"order":"5"},{"age":10,"order":"6"},{"age":10,"order":"7"},{"age":10,"order":"8"},{"age":10,"order":"9"},{"age":10,"order":"10"},{"age":10,"order":"11"}]}sort_by(people, &age)[{"age":10,"order":"1"},{"age":10,"order":"2"},{"age":10,"order":"3"},{"age":10,"order":"4"},{"age":10,"order":"5"},{"age":10,"order":"6"},{"age":10,"order":"7"},{"age":10,"order":"8"},{"age":10,"order":"9"},{"age":10,"order":"10"},{"age":10,"order":"11"}]
{"empty_list":[],"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}sort_by(people, name)null
{"empty_list":[],"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}sort_by(empty_list, &age)[]
{"empty_list":[],"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}sort_by(people, &extra)null
{"empty_list":[],"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}sort_by(people, &age)[{"age":10,"age_str":"10","bool":true,"name":3},{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":50,"age_str":"50","bool":false,"name":"d"}]
{"empty_list":[],"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}sort_by(people, &bool)null
{"empty_list":[],"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}sort_by(people, &age_str)[{"age":10,"age_str":"10","bool":true,"name":3},{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":50,"age_str":"50","bool":false,"name":"d"}]
{"empty_list":[],"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}sort_by(people, &to_number(age_str))[{"age":10,"age_str":"10","bool":true,"name":3},{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":50,"age_str":"50","bool":false,"name":"d"}]
{"empty_list":[],"people":[{"age":20,"age_str":"20","bool":true,"extra":"foo","name":"a"},{"age":40,"age_str":"40","bool":false,"extra":"bar","name":"b"},{"age":30,"age_str":"30","bool":true,"name":"c"},{"age":50,"age_str":"50","bool":false,"name":"d"},{"age":10,"age_str":"10","bool":true,"name":3}]}sort_by(people, &name)null
split
array[string] split string $subjectstring $searchnumber $count
Arguments
NamePresenceTypeDescription
$subjectrequiredstringSubject string
$searchrequiredstringText separator
$countoptionalnumberNumber of splits to perform
Returnsarray[string]

Given the subject string, split() breaks on ocurrences of the string search and returns an array.

The split() function returns an array containing each partial string between occurrences of search. If subject contains no occurrences of the search text, an array containing just the original subject string will be returned.

The count optional parameter specifies the maximum number of split points within the search string. If this parameter is omitted, all occurrences are split. If count is not an integer or is negative, an error MUST be raised.

If count is equal to 0, split() returns an array containing a single element, the subject string.

Otherwise, the split() function breaks on occurrences of the search string up to count times. The last string in the resulting array containing the remaining contents of the subject string unmodified.

Examples
GivenExpressionResult
"average|-|min|-|max|-|mean|-|median"split(average|-|min|-|max|-|mean|-|median, '|-|', `3`)["average","min","max","mean|-|median"]
"average|-|min|-|max|-|mean|-|median"split(average|-|min|-|max|-|mean|-|median, '|-|', `2`)["average","min","max|-|mean|-|median"]
"average|-|min|-|max|-|mean|-|median"split(average|-|min|-|max|-|mean|-|median, '|-|', `1`)["average","min|-|max|-|mean|-|median"]
"average|-|min|-|max|-|mean|-|median"split(average|-|min|-|max|-|mean|-|median, '|-|', `0`)["average|-|min|-|max|-|mean|-|median"]
"average|-|min|-|max|-|mean|-|median"split(average|-|min|-|max|-|mean|-|median, '-')["average|","|min|","|max|","|mean|","|median"]
nullsplit(all chars, )["a","l","l"," ","c","h","a","r","s"]
nullsplit(/, /)["",""]
"average|-|min|-|max|-|mean|-|median"split(average|-|min|-|max|-|mean|-|median, '|-|')["average","min","max","mean","median"]
starts_with
boolean starts_with string $subjectstring $prefix
Arguments
NamePresenceTypeDescription
$subjectrequiredstring
$prefixrequiredstring
Returnsboolean
Returns true if the $subject starts with the $prefix, otherwise this function returns false.
Examples
GivenExpressionResult
"foobarbaz"starts_with(@, 'foo')true
"foobarbaz"starts_with(@, 'baz')false
"foobarbaz"starts_with(@, 'f')true
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}starts_with(str, 'Str')true
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}starts_with(str, 'String')false
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}starts_with(str, 0)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}starts_with(str, 'S')true
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}starts_with(str, 'St')true
sum
number sum array[number] $collection
Arguments
NamePresenceTypeDescription
$collectionrequiredarray[number]
Returnsnumber

Returns the sum of the provided array argument.

An empty array will produce a return value of 0.

Examples
GivenExpressionResult
[]sum(@)0
[10,15]sum(@)25
[10,false,20]sum(@)null
[10,false,20]sum([].to_number(@))30
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}sum(array[].to_number(@))111
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}sum(array)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}sum(numbers)11
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}sum(empty_list)0
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}sum(decimals)0.71
to_array
array to_array any $arg
Arguments
NamePresenceTypeDescription
$argrequiredany
Returnsarray
  • array - Returns the passed in value.
  • number/string/object/boolean/null - Returns a one element array containing the passed in argument.
Examples
GivenExpressionResult
nullto_array(true)[true]
nullto_array()[{"foo":"bar"}]
nullto_array(0)[0]
nullto_array('string')["string"]
nullto_array()[1,2]
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}to_array('foo')["foo"]
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}to_array(0)[0]
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}to_array(objects)[{"bar":"baz","foo":"bar"}]
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}to_array()[1,2,3]
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}to_array(false)[false]
to_number
number to_number any $arg
Arguments
NamePresenceTypeDescription
$argrequiredany
Returnsnumber
  • string - Returns the parsed number. Any string that conforms to the json-number production is supported. Note that the floating number support will be implementation specific, but implementations should support at least IEEE 754-2008 binary64 (double precision) numbers, as this is generally available and widely used.

  • number - Returns the passed in value.

  • array - null

  • object - null

  • boolean - null

  • null - null

Examples
GivenExpressionResult
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}to_number()null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}to_number()null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}to_number()null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}to_number('1.0')1
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}to_number('1.1')1.1
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}to_number('4')4
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}to_number(notanumber)null
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}to_number(false)null
to_string
string to_string any $arg
Arguments
NamePresenceTypeDescription
$argrequiredany
Returnsstring
  • string - Returns the passed in value.

  • number/array/object/boolean - The JSON encoded value of the object. The JSON encoder should emit the encoded JSON value without adding any additional new lines.

Examples
GivenExpressionResult
nullto_string(2)"2"
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}to_string('foo')"foo"
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}to_string(1.2)"1.2"
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}to_string()"[0,1]"
trim
string trim string $subjectstring $chars
Arguments
NamePresenceTypeDescription
$subjectrequiredstringSubject string
$charsoptionalstringSet of characters to be removed
Returnsstring

Given the subject string, trim() removes the leading and trailing characters found in chars.

The chars optional parameter represents a set of characters to be removed from the subject string. If this parameter is not specified, or is an empty string, whitespace characters are removed from the subject string.

Examples
GivenExpressionResult
" subject string "trim(@, 'gsu ')"bject strin"
" subject string "trim(@)"subject string"
" subject string "trim(@, '')"subject string"
" subject string "trim(@, ' ')"subject string"
" subject string "trim(@, 's')" subject string "
" subject string "trim(@, 'su')" subject string "
" subject string "trim(@, 'su ')"bject string"
trim_left
string trim_left string $subjectstring $chars
Arguments
NamePresenceTypeDescription
$subjectrequiredstringSubject string
$charsoptionalstringSet of characters to be removed
Returnsstring

Given the subject string, trim_left() removes the leading characters found in chars.

Like the trim() function, the chars optional string parameter represents a set of characters to be removed. trim_left() defaults to removing whitespace characters if chars is not specified or is an empty string.

Examples
GivenExpressionResult
" subject string "trim_left(@)"subject string "
" subject string "trim_left(@, 's')" subject string "
" subject string "trim_left(@, 'su')" subject string "
" subject string "trim_left(@, 'su ')"bject string "
" subject string "trim_left(@, 'gsu ')"bject string "
trim_right
string trim_right string $subjectstring $chars
Arguments
NamePresenceTypeDescription
$subjectrequiredstringSubject string
$charsoptionalstringSet of characters to be removed
Returnsstring

Given the subject string, trim_right() removes the trailing characters found in chars.

Like the trim() function, the chars optional string parameter represents a set of characters to be removed. trim_right() defaults to removing whitespace characters if chars is not specified or is an empty string.

Examples
GivenExpressionResult
" subject string "trim_right(@, 'gsu ')" subject string"
" subject string "trim_right(@)"subject string "
" subject string "trim_right(@, 's')" subject string "
" subject string "trim_right(@, 'su')" subject string "
" subject string "trim_right(@, 'su ')" subject string"
type
string type array|object|string|number|boolean|null $subject
Arguments
NamePresenceTypeDescription
$subjectrequiredarray|object|string|number|boolean|null
Returnsstring

Returns the JavaScript type of the given $subject argument as a string value.

The return value MUST be one of the following:

  • number
  • string
  • boolean
  • array
  • object
  • null
Examples
GivenExpressionResult
falsetype(@)"boolean"
"foo"type(@)"string"
nulltype(@)"null"
["abc"]type(@)"array"
truetype(@)"boolean"
{"abc":"123"}type(@)"object"
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}type(false)"boolean"
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}type(@)"object"
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}type('abc')"string"
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}type(1)"number"
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}type(2)"number"
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}type()"null"
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}type()"object"
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}type(true)"boolean"
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}type()"array"
123type(@)"number"
123.05type(@)"number"
upper
string upper string $subject
Arguments
NamePresenceTypeDescription
$subjectrequiredstringSubject string
Returnsstring
Returns the uppercase subject string.
Examples
GivenExpressionResult
"string"upper(@)"STRING"
values
array values object $obj
Arguments
NamePresenceTypeDescription
$objrequiredobject
Returnsarray

Returns the values of the provided object. Note that because JSON hashes are inheritently unordered, the values associated with the provided object obj are inheritently unordered. Implementations are not required to return values in any specific order. For example, given the input:

{"a": "first", "b": "second", "c": "third"}

The expression values(@) could have any of these return values:

  • ["first", "second", "third"]

  • ["first", "third", "second"]

  • ["second", "first", "third"]

  • ["second", "third", "first"]

  • ["third", "first", "second"]

  • ["third", "second", "first"]

If you would like a specific order, consider using the sort or sort_by functions.

Examples
GivenExpressionResult
falsevalues(@)null
{"bar":"bam","foo":"baz"}values(@)["baz","bam"]
["a","b"]values(@)null
Show more..
{"array":[-1,3,4,5,"a","100"],"decimals":[1.01,1.2,-1.5],"empty_hash":{},"empty_list":[],"false":false,"foo":-1,"null_key":null,"numbers":[-1,3,4,5],"objects":{"bar":"baz","foo":"bar"},"str":"Str","strings":["a","b","c"],"zero":0}values(foo)null
zip
array[array[any]] zip array[any] $arg
Arguments
NamePresenceTypeDescription
$argrequiredarray[any]
Returnsarray[array[any]]
Accepts one or more arrays as arguments and returns an array of arrays in which the i-th array contains the i-th element from each of the argument arrays. The returned array is truncated to the length of the shortest argument array.
Examples
GivenExpressionResult
nullzip()[["a",1],["b",2]]
nullzip()[["a",1],["b",2]]