Introduction
gq uses jq 1.8 as its reference implementation.
For all supported features, gq should work like jq, plus extra operations on geometries.
gq aims to support a minimal subset of most-used core jq functionality, just enough to be useful
in service of its main function of manipulating GeoJSON.
Supported jq Features
See jq 1.8 manual
jq Feature | Example |
|---|---|
| Identity | . |
| Object Identifier-Index | .foo, .foo.bar |
| Object Index | .["foo"] |
| Array Index | .[2] |
| Array/String Slice | .[2:4] |
| Pipe | .a | .b | .c |
| Parenthesis | (. + 2) * 5 |
| JSON data types | 1, "a", true, null, [], {}, etc. |
| Array construction | [1, 2, 3] |
| Object construction | {"a": 42, "b": 17} |
| Addition | +/add |
| Subtraction | - |
| Multiplication, division, modulo | *, /, % |
| Conditional operators | ==, != |
| Comparison operators | >, >=, <, <= |
| Boolean operators | and, or, not |
| Sorting arrays | sort |
| Length | length |
| Map | map |
| Plain assignment1 | = |
| Update assignment1 | |= |
| Arithmetic update assignment1 | +=, -=, *=, /=, %= |
| Variable Binding | .realnames as $names |
Unsupported Features
These features are out of scope for this tool with no plans for implementation:
- iterators
- generators
- user-defined functions
- scoping
- streaming
- modules
Notable Differences from jq
gq does not support outputting streams of non-JSON data via iterators (.[]) and generators
(,). Rather, since gq is very JSON and GeoJSON focused, every transformation produces valid JSON.
This means, for example, that there is no select since that function will produce no output if the
condition does not match, and “no output” is not valid JSON.
map and filter
It is of course still possible to manipulate collections of data. Instead of:
[.[] | . + 1]
You would use map (this is also valid jq):
map(. + 1)
And instead of:
map(select(. >= 2))
You would use filter:
filter(. >= 2)