JMESPath · lesson 12 of 15 · Functions

Counting & math

length, avg, min, max and sum work on arrays (and length works on strings and objects too).

Examples

Example 1Count, average, youngest, oldest

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

[length(members), avg(members[*].age), min(members[*].age), max(members[*].age)]
  1. length(members) How many members → 4.
  2. avg(members[*].age) The mean age → 37.5.
  3. min(members[*].age) The youngest → 28.
  4. max(members[*].age) The oldest → 45.

Result

[4,37.5,28,45]

Try it in the playground

Good to know

  • sum is there too — and, like abs, it returns a floating-point number: sum(members[*].age) prints 150.0.

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.