JMESPath query examples
masterThe following examples demonstrate different capabilities of the JMESPath query language using jmespath.search:
- Object Projection: Selecting a sub-object.
- List Projection: Using
[*]to extract specific fields from every object in an array. - Filtering: Using
[? ...]to filter array elements based on a condition (note that literal values in expressions often use backticks, e.g.,`30`).
// Object Projection
jmespath.search({foo: {bar: {baz: [0, 1, 2, 3, 4]}}}, "foo.bar")
// returns { baz: [ 0, 1, 2, 3, 4 ] }
// List Projection
jmespath.search({"foo": [{"first": "a", "last": "b"}, {"first": "c", "last": "d"}]}, "foo[*].first")
// returns [ 'a', 'c' ]
// Filtering
jmespath.search({"foo": [{"age": 20}, {"age": 25}, {"age": 30}, {"age": 35}, {"age": 40}]}, "foo[?age > `30`]")
// returns [ { age: 35 }, { age: 40 } ]