### JMESPath Function Result Example Source: https://jmespath.org/tutorial.html A basic example showing a function result. ```text 3 ``` ```json { "people": [ { "name": "b", "age": 30, "state": {"name": "up"} }, { "name": "a", "age": 50, "state": {"name": "down"} }, { "name": "c", "age": 40, "state": {"name": "up"} } ] } ``` -------------------------------- ### Slice Expression Examples Source: https://jmespath.org/specification.html Examples demonstrating various slice configurations including steps and negative indices. ```text 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] ``` -------------------------------- ### Index Access Examples Source: https://jmespath.org/specification.html Examples of accessing array elements by index, including handling out-of-bounds indices. ```text 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 ``` -------------------------------- ### MultiSelect Hash Examples Source: https://jmespath.org/specification.html Various examples demonstrating how to use multi-select-hash to extract and map data from JSON objects. ```text 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} ``` -------------------------------- ### Input JSON for no breaking changes example Source: https://jmespath.org/proposals/nested-expressions.html Sample JSON data used as input for the no breaking changes example. ```json { "foo": { "baz": { "abc": 123, "bar": 456 } } } ``` -------------------------------- ### MultiSelect List examples Source: https://jmespath.org/specification.html Examples of multi-select list expressions with search(), showing extraction of multiple fields and handling of missing keys. ```text 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] ``` -------------------------------- ### Simple filter syntax example Source: https://jmespath.org/proposals/filter-expressions.html An example of a basic filter syntax that was considered for JMESPath. ```text foo[bar == baz] ``` -------------------------------- ### Pipe Expression Examples Source: https://jmespath.org/specification.html Various examples of using the pipe operator with the search function. ```text 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 expression examples Source: https://jmespath.org/specification.html Examples of JMESPath or expressions using search() with various inputs, showing the first truthy value or null. ```text 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" ``` -------------------------------- ### Multi-select hash literal example Source: https://jmespath.org/proposals/filter-expressions.html An example of using literal expressions within a multi-select-hash. ```text {a: foo.bar, b: `some string`} ``` -------------------------------- ### And expression examples Source: https://jmespath.org/proposals/improved-filters.html Examples of and expressions in JMESPath, showing truth-like and false-like value handling. ```jmespath 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}] ``` -------------------------------- ### And expression examples Source: https://jmespath.org/specification.html Examples of JMESPath and expressions using search() with various inputs, showing the right operand if left is truthy, otherwise the left operand. ```text 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}] ``` -------------------------------- ### search function example Source: https://jmespath.org/specification.html Example of applying the search function to a JSON document. The result is a valid JSON value. ```text search(foo, {"foo": "bar"}) -> "bar" ``` -------------------------------- ### Paren expression example Source: https://jmespath.org/specification.html Example of using a parenthesized expression with the search() function, demonstrating precedence override. ```text search(foo[?(a == `1` || b ==`2`) && c == `5`], {"foo": [{"a": 1, "b": 2, "c": 3}, {"a": 3, "b": 4}]}) -> [] ``` -------------------------------- ### Not expression examples Source: https://jmespath.org/proposals/improved-filters.html Examples of not expressions, negating truth-like and false-like values. ```jmespath search(!True, {"True": true}) -> false search(!False, {"False": false}) -> true search(!Number, {"Number": 5}) -> false search(!EmptyList, {"EmptyList": []}) -> true ``` -------------------------------- ### Valid expression reference examples Source: https://jmespath.org/proposals/exptype.html Demonstrates valid usage of the expression reference syntax with the sort_by function. ```text sort_by(people, &foo.bar.baz) sort_by(people, &foo.bar[0].baz) sort_by(people, &to_number(foo[0].bar)) ``` -------------------------------- ### Not expression examples Source: https://jmespath.org/specification.html Examples of not expressions with search(), showing negation of truth-like and false-like values. ```text search(!True, {"True": true}) -> false search(!False, {"False": false}) -> true search(!Number, {"Number": 5}) -> false search(!EmptyList, {"EmptyList": []}) -> true ``` -------------------------------- ### Wildcard Expression Examples Source: https://jmespath.org/specification.html Examples of list wildcard and hash wildcard expressions with their results. Note that null results are omitted and hash values may be in any order. ```text 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] ``` -------------------------------- ### Subexpression Evaluation Example Source: https://jmespath.org/specification.html Step-by-step evaluation of the expression 'foo.bar' against a JSON document. ```text left-evaluation = search("foo", {"foo": {"bar": "baz"}}) -> {"bar": "baz"} result = search("bar": {"bar": "baz"}) -> "baz" ``` -------------------------------- ### Input JSON for nested branch with multi-select Source: https://jmespath.org/proposals/nested-expressions.html Sample JSON data used as input for the nested branch with multi-select example. ```json { "foo": { "baz": [ { "bar": "a", "bam": "b", "boo": "c" }, { "bar": "d", "bam": "e", "boo": "f" } ], "qux": ["zero"] } } ``` -------------------------------- ### Additional Subexpression Examples Source: https://jmespath.org/specification.html Various scenarios demonstrating subexpression evaluation results. ```text 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" ``` -------------------------------- ### Examples of literal expressions Source: https://jmespath.org/specification.html Shows how literal expressions evaluate to JSON values. Note the escaped backtick in the second example and the use of literals in multi-select hashes. ```text 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"} ``` -------------------------------- ### Identifier search examples Source: https://jmespath.org/specification.html Examples of using the search function with identifiers, including unquoted, quoted, and escaped identifiers. Missing keys return null. ```text 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" ``` -------------------------------- ### Example data with Unicode keys Source: https://jmespath.org/proposals/improved-identifiers.html Sample JSON data used to illustrate the proposed identifier syntax with Unicode characters. ```json {"foo": [{"✓": "✓"}, {"✓": "✗"}]} ``` -------------------------------- ### Example Data with Multiple Matches Source: https://jmespath.org/examples.html Sample data structure where multiple elements share the same ID. ```json { "people": [ { "general": { "id": 100, "age": 20 }, "history": { } }, { "general": { "id": 101, "age": 30 }, "history": { } }, { "general": { "id": 100, "age": 30 }, "history": { } } ] } ``` -------------------------------- ### Filter Expression Examples Source: https://jmespath.org/specification.html Three examples of filter expressions using the search function, showing equality and comparison with literal values and field references. ```jmespath 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}] ``` -------------------------------- ### Input JSON for Pipe Expression Source: https://jmespath.org/examples.html The input JSON document used for the pipe expression example. ```json { "locations": [ {"name": "Seattle", "state": "WA"}, {"name": "New York", "state": "NY"}, {"name": "Bellevue", "state": "WA"}, {"name": "Olympia", "state": "WA"} ] } ``` -------------------------------- ### abs Function Evaluation Example Source: https://jmespath.org/proposals/functions.html Step-by-step evaluation of the abs function with valid and invalid inputs. ```text {"foo": -1, "bar": "2"} ``` ```text search(foo, {"foo": -11, "bar": 2"}) -> -1 ``` ```text abs(-1) -> 1 ``` ```text search(foo, {"foo": -1, "bar": 2"}) -> "2" ``` ```text search(to_number(bar), {"foo": -1, "bar": "2"}) ``` ```text search(bar, {"foo": -1, "bar": "2"}) -> "2" # Validate "2" passes the type check for to_number, which it does. to_number("2") -> 2 ``` ```text search(to_number(bar), {"foo": -1, "bar": "2"}) -> 2 ``` ```text abs(2) -> 2 ``` -------------------------------- ### Input JSON for nested branch expressions Source: https://jmespath.org/proposals/nested-expressions.html Sample JSON data used as input for the nested branch expression example. ```json { "foo": { "baz": [ { "bar": "abc" }, { "bar": "def" } ], "qux": ["zero"] } } ``` -------------------------------- ### Example input JSON for projection limitation Source: https://jmespath.org/proposals/pipes.html Sample JSON document used to illustrate the limitation of projections when trying to operate on the result as a list. ```json { "foo": { "a": { "bar": [1, 2, 3] }, "b": { "bar": [4, 5, 6] } } } ``` -------------------------------- ### sort_by function with string expressions Source: https://jmespath.org/proposals/exptype.html Example usage of the sort_by function where expressions are passed as strings. ```text sort_by(people, `age`) sort_by(people, `foo.bar.baz`) ``` -------------------------------- ### Example usage of current-node in a function Source: https://jmespath.org/proposals/functions.html Demonstrates using the current-node token (@) within a function to count elements in an object. ```text foo[].[count(@), bar] ``` -------------------------------- ### Lua long bracket notation example Source: https://jmespath.org/proposals/raw-string-literals.html An example of Lua's long bracket notation for raw strings, which uses customizable delimiters to avoid character escaping. ```lua [==[foo=bar]==] -- parsed as "foo=bar" ``` -------------------------------- ### Multiselect List Input Data Source: https://jmespath.org/tutorial.html The input data used for the multiselect list example. ```json { "people": [ { "name": "a", "state": {"name": "up"} }, { "name": "b", "state": {"name": "down"} }, { "name": "c", "state": {"name": "up"} } ] } ``` -------------------------------- ### JMESPath Query Result Example Source: https://jmespath.org/ Displays the expected output format when querying a JSON object containing location data. ```json { "WashingtonCities": "Bellevue, Olympia, Seattle" } ``` -------------------------------- ### Examples of raw string literals Source: https://jmespath.org/specification.html Demonstrates that raw string literals preserve characters literally, including spaces, brackets, backslashes, and do not expand unicode or escape sequences. ```text search('foo', "") -> "foo" search(' bar ', "") -> " bar " search('[baz]', "") -> "[baz]" search('[baz]', "") -> "[baz]" search('\u03a6', "") -> "\u03a6" search('\\', "") -> "\\" ``` -------------------------------- ### Using the current-node token Source: https://jmespath.org/specification.html Example of using the @ token to reference the current node within a projection to calculate length and access a field. ```text foo[].[length(@), bar] ``` -------------------------------- ### Example JSON object for sorting Source: https://jmespath.org/proposals/exptype.html A sample JSON structure containing a list of people with various attributes used to demonstrate sorting limitations. ```json { "people": [ {"age": 20, "age_str": "20", "bool": true, "name": "a", "extra": "foo"}, {"age": 40, "age_str": "40", "bool": false, "name": "b", "extra": "bar"}, {"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} ] } ``` -------------------------------- ### JMESPath Pipe Expression Example Source: https://jmespath.org/examples.html A demonstration of a pipe expression that filters locations in WA, sorts them, takes the last two, and joins them into a multiselect hash. ```jmespath locations[?state == 'WA'].name | sort(@)[-2:] | {WashingtonCities: join(', ', @)} ``` ```json { "WashingtonCities": "Olympia, Seattle" } ``` -------------------------------- ### Sort array with sort_by Source: https://jmespath.org/examples.html This example demonstrates sorting the Contents array by the Date key. The expression uses an expression type &Date and a projection [*] to format the output. ```jmespath sort_by(Contents, &Date)[*].{Key: Key, Size: Size} ``` ```json [ { "Key": "logs/baz", "Size": 329 }, { "Key": "logs/aa", "Size": 308 }, { "Key": "logs/qux", "Size": 297 }, { "Key": "logs/bar", "Size": 604 }, { "Key": "logs/foo", "Size": 647 }, { "Key": "logs/bb", "Size": 303 } ] ``` ```json { "Contents": [ { "Date": "2014-12-21T05:18:08.000Z", "Key": "logs/bb", "Size": 303 }, { "Date": "2014-12-20T05:19:10.000Z", "Key": "logs/aa", "Size": 308 }, { "Date": "2014-12-20T05:19:12.000Z", "Key": "logs/qux", "Size": 297 }, { "Date": "2014-11-20T05:22:23.000Z", "Key": "logs/baz", "Size": 329 }, { "Date": "2014-12-20T05:25:24.000Z", "Key": "logs/bar", "Size": 604 }, { "Date": "2014-12-20T05:27:12.000Z", "Key": "logs/foo", "Size": 647 } ] } ``` -------------------------------- ### Array slice expression syntax Source: https://jmespath.org/proposals/array-slices.html The general syntax for array slice expressions, showing the optional start, stop, and step positions. ```jmepath [start:stop:step] ``` -------------------------------- ### Paren expression example Source: https://jmespath.org/proposals/improved-filters.html Example of a parenthesized expression overriding precedence in a filter. ```jmespath search(foo[?(a == `1` || b ==`2`) && c == `5`], {"foo": [{"a": 1, "b": 2, "c": 3}, {"a": 3, "b": 4}]}) -> [] ``` -------------------------------- ### Sample input data for the JMESPath expression Source: https://jmespath.org/examples.html This is the sample input JSON data used in the example. It contains a top-level 'reservations' key with a list of objects, each having an 'instances' key that is also a list. Each instance has 'type', 'state', and 'tags' fields. ```json { "reservations": [ { "instances": [ {"type": "small", "state": {"name": "running"}, "tags": [{"Key": "Name", "Values": ["Web"]}, {"Key": "version", "Values": ["1"]}]}, {"type": "large", "state": {"name": "stopped"}, "tags": [{"Key": "Name", "Values": ["Web"]}, {"Key": "version", "Values": ["1"]}]} ] }, { "instances": [ {"type": "medium", "state": {"name": "terminated"}, "tags": [{"Key": "Name", "Values": ["Web"]}, {"Key": "version", "Values": ["1"]}]}, {"type": "xlarge", "state": {"name": "running"}, "tags": [{"Key": "Name", "Values": ["DB"]}, {"Key": "version", "Values": ["1"]}]} ] } ] } ``` -------------------------------- ### Literal JSON array filter example Source: https://jmespath.org/proposals/filter-expressions.html An example of filtering elements where a key matches a literal list. ```text [foo == [2]] ``` -------------------------------- ### Sample Data for Pipe Expressions Source: https://jmespath.org/specification.html Input data used to demonstrate projection behavior. ```json {"foo": [{"bar": ["first1", "second1"]}, {"bar": ["first2", "second2"]}]} ``` -------------------------------- ### Ambiguous filter expression example Source: https://jmespath.org/proposals/filter-expressions.html An example of an ambiguous expression that could be interpreted as either a filter or a multiselect-list. ```text [foo] ``` -------------------------------- ### starts_with function Source: https://jmespath.org/specification.html Checks if a subject string begins with a specified prefix. ```text boolean starts_with(string $subject, string $prefix) ``` -------------------------------- ### Users data for And Expressions Source: https://jmespath.org/proposals/improved-filters.html Example data for the And Expressions section: a list of user accounts with type and allowed_hosts, used to illustrate filtering for admin users with access to host c. ```json { "users": [ {"name": "user1", "type": "normal"", "allowed_hosts": ["a", "b"]}, {"name": "user2", "type": "admin", "allowed_hosts": ["a", "b"]}, {"name": "user3", "type": "normal", "allowed_hosts": ["c", "d"]}, {"name": "user4", "type": "admin", "allowed_hosts": ["c", "d"]}, {"name": "user5", "type": "normal", "allowed_hosts": ["c", "d"]}, {"name": "user6", "type": "normal", "allowed_hosts": ["c", "d"]} ] } ``` -------------------------------- ### Ambiguous JSON literal example Source: https://jmespath.org/proposals/raw-string-literals.html An example of a JMESPath expression that causes inconsistent parsing behavior across different implementations. ```text `[1` ``` -------------------------------- ### JSON data example for filter expressions Source: https://jmespath.org/proposals/filter-expressions.html Example JSON object used to illustrate filtering list elements by a specific value. ```json {"foo": [{"state": "WA", "value": 1}, {"state": "WA", "value": 2}, {"state": "CA", "value": 3}, {"state": "CA", "value": 4}]} ``` -------------------------------- ### JMESPath literal expression examples Source: https://jmespath.org/proposals/filter-expressions.html Examples of literal expressions using backticks. Shows that string literals can omit quotes, and that backticks can be escaped. ```jmespath `foobar` -> "foobar" `"foobar"` -> "foobar" `123` -> 123 `"123"` -> "123" `123.foo` -> "123.foo" `true` -> true `"true"` -> "true" `truee` -> "truee" ``` -------------------------------- ### Function argument resolution process Source: https://jmespath.org/proposals/exptype.html Demonstration of the current argument resolution process which results in null values when evaluating expressions against the root node. ```text sort_by(people, age) # 1. resolve people arg1 = search(people, ) -> [{"age": ...}, {...}] # 2. resolve age arg2 = search(age, ) -> null sort_by([{"age": ...}, {...}], null) ``` -------------------------------- ### Unary expression if statement Source: https://jmespath.org/proposals/improved-filters.html Example of a unary expression in an if statement, checking a boolean variable directly. ```c if (allowed_access) { ... } ``` -------------------------------- ### Pipe Expression Evaluation Steps Source: https://jmespath.org/tutorial.html The evaluation steps for the pipe expression. ```text evaluate(people[*].first, inputData) -> ["James", "Jacob", "Jayden"] evaluate([0], ["James", "Jacob", "Jayden"]) -> "James" ``` -------------------------------- ### Select second half of array Source: https://jmespath.org/tutorial.html Selects elements starting from index 5 to the end of the array. ```json [ 5, 6, 7, 8, 9 ] ``` -------------------------------- ### Slice Expression Grammar Source: https://jmespath.org/specification.html Defines the syntax for slice expressions using start, stop, and step components. ```text slice-expression = [number] ":" [number] [ ":" [number] ] ``` -------------------------------- ### Converting types with to_number Source: https://jmespath.org/specification.html Example of using the to_number function within a projection to convert elements of an array to numbers. ```text search([].to_number(@), `["1", "2", "3", "notanumber", true]`) -> [1, 2, 3] ``` -------------------------------- ### Comparison of literal and raw string expressions Source: https://jmespath.org/specification.html Shows that a raw string literal 'foo' evaluates to the same value as the literal expression `"foo"`. ```text search(`"foo"`, "") -> "foo" search('foo', "") -> "foo" ``` -------------------------------- ### Negated unary expression if statement Source: https://jmespath.org/proposals/improved-filters.html Example of a negated unary expression in an if statement, checking the negation of a boolean variable. ```c if (!allowed_access) { ... } ``` -------------------------------- ### Compliance test change for hyphen-prefixed identifier Source: https://jmespath.org/proposals/improved-identifiers.html Diff showing required change because an unquoted identifier cannot start with a hyphen. ```diff - "expression": "foo.-1", + "expression": "foo.\"-1\"", "result": "bar" } ``` -------------------------------- ### Users data for Unary Expressions Source: https://jmespath.org/proposals/improved-filters.html Example data for the Unary Expressions section: a list of users with is_admin and disabled flags, used to illustrate filtering for enabled admin users. ```json { "users": [ {"name": "user1", "is_admin": false, "disabled": false}, {"name": "user2", "is_admin": true, "disabled": true}, {"name": "user3", "is_admin": false, "disabled": false}, {"name": "user4", "is_admin": true, "disabled": false}, {"name": "user5", "is_admin": false, "disabled": true}, {"name": "user6", "is_admin": false, "disabled": false} ] } ``` -------------------------------- ### Standard if statement Source: https://jmespath.org/proposals/improved-filters.html Example of a standard if statement in C or Java, used to contrast with unary expressions in the Unary Expressions section. ```c if (foo == bar) { ... } ```