JMESPath · lesson 7 of 15 · Filtering

Filters & literals

[?condition] keeps the elements for which the condition is true. Numbers, booleans and null are written as JSON literals in backticks — `30` — while plain strings can use single quotes: 'dev'.

Examples

Example 1Compare with a number

Document

{
  "team": "Platform",
  "office": { "city": "Berlin", "floor": 3 },
  "members": [
    { "name": "Ada", "age": 36, "role": "lead", "active": true,
      "email": "[email protected]", "skills": ["rust", "sql"] },
    { "name": "Linus", "age": 28, "role": "dev", "active": true,
      "email": null, "skills": ["c", "shell"] },
    { "name": "Grace", "age": 45, "role": "dev", "active": false,
      "skills": ["cobol"] },
    { "name": "Alan", "age": 41, "role": "qa", "active": true,
      "email": "[email protected]", "skills": [] }
  ]
}

Query

members[?age > `30`].name
  1. [? Start of a filter: keep the elements for which the test is true.
  2. age > `30` Compares age with `30` — a number literal, which must be written in backticks.
  3. .name Then project their names.

Result

["Ada","Grace","Alan"]

Try it in the playground

Example 2Compare with a string

Document

{
  "team": "Platform",
  "office": { "city": "Berlin", "floor": 3 },
  "members": [
    { "name": "Ada", "age": 36, "role": "lead", "active": true,
      "email": "[email protected]", "skills": ["rust", "sql"] },
    { "name": "Linus", "age": 28, "role": "dev", "active": true,
      "email": null, "skills": ["c", "shell"] },
    { "name": "Grace", "age": 45, "role": "dev", "active": false,
      "skills": ["cobol"] },
    { "name": "Alan", "age": 41, "role": "qa", "active": true,
      "email": "[email protected]", "skills": [] }
  ]
}

Query

members[?role == 'dev'].name
  1. 'dev' A raw string literal in single quotes. The JSON literal `"dev"` works too.

Result

["Linus","Grace"]

Try it in the playground

Good to know

  • The comparison operators are ==, !=, <, <=, > and >=.
  • Decimal literals such as `9.5` don't evaluate correctly in this build yet; whole numbers, strings, booleans and null are fine.

About jsonquery

Query, format and learn JSON with jq, JSONPath, JMESPath and JSON Pointer. It is the engine of the desktop app, run in your browser.

Engine
The desktop app’s, compiled to WebAssembly
Licence
MIT (the engine and the app)
Source
GitHub
Contact
The contact form (private)
Public issues
GitHub
Legal
Privacy policy

Known limitations: a file over 10 MB opens read-only and one over 512 MB does not open here; the desktop app has no such limit.