Sign inTry it

JMESPath

JMESPath is a query language for JSON. You write an expression that extracts and reshapes values from a document. For example, people[?age>\20\].name returns the names of everyone over 20. One short expression can replace a block of parsing code.

Updated

How JMESPath works

An expression walks the JSON. It selects keys, indexes arrays, and filters items inside square brackets with a condition. It can also project fields from each item in a list. The result is a new JSON value. The JMESPath tutorial covers the syntax with examples.

Why it matters for AI agents

Agents receive large JSON responses from APIs. A short expression picks out the fields the next step needs, so the model sees less noise and the code stays small.

Wield and JMESPath

Wield recipes use JMESPath in several places:

WhereWhat it does
whenSkips a step when the result is falsy
foreachRuns a step once per item in an array. max defaults to 10 and is at most 20
assertChecks a response. It must be truthy
jsonExtracts variables from the parsed body
valueComputes values from params, earlier steps and the run's start time

Wield uses JMESPath Community Edition, which adds let, arithmetic, from_items, zip and group_by. One trap catches most authors. Inside a filter, params.x refers to the current element, not to the recipe's params. Bind the value first with let.

FAQ

JMESPath vs jq?

JMESPath has its own spec and tutorial at jmespath.org. jq is a separate tool with its own language. The two are not interchangeable, so check which one your tool expects.

Can JMESPath filter arrays?

Yes. Square brackets with a question mark filter the items, as in people[?age>\20\].name. Only the items where the condition is true are kept.

Sources

  1. JMESPathjmespath.org
  2. JMESPath tutorialjmespath.org