#2425·jq

Opportunity: operator precedence table

Author: mikezCreated Apr 10, 2022Updated Aug 21, 2026
Labelsdocswiki

Does anyone here think operator precedence tables are helpful? I do. :) (Examples: Python and JavaScript.)

Is there already such a table for jq? If not, would it make sense to include it in the Wiki or elsewhere?

Example table (feel free to copy and change)

Here's a first draft based on Rosetta Code, parser.y, some simplifying assumptions, and guesses. Somebody who knows the codebase better than me, would be a good candidate to correct and extend this. :)

Order: from highest precedence (most binding) to lowest precedence (least binding).

Operator Description
x? Error Suppression
-x Negative
*, /, % Multiplication, Division, Modulo
+, - Addition, Subtraction
==, !=, <, >,<=, >= Comparisons
and Boolean AND
or Boolean OR
=, |=, +=, -=, *=, /=, %= Update-assignment
// Alternative
, Comma
| Pipe
label $variable Labels
try … catch … Try expression
if … then … end Conditional expression
foreach … as … (…) Loop expression
reduce … as … (…) Reduce expression
… as $variable Variable definition expression
def … ; … Function expression