Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Features

First Class FeatureCollections

Any function that operates on an array can also take a FeatureCollection where each item is a Feature.

Automatic Array from Multiple Input Files

In jq, there is an optional command line argument --slurp/-s which puts the entire input stream into an array and runs the program against that.

In gq, this happens automatically if there are multiple input files.

Any number of files containing JSON or GeoJSON can be passed in and they will appended in order to an array that can then be operated on.

As an example, this command:

gq '.' feature.json geometry.json

will return an array containing a Feature and a Geometry.

If only one file is passed in, no array will be created.

File Arguments

Input files are automatically available as variables with a specific naming scheme.

File arguments have a dollar sign ($) prefix followed by the argument index:

  • $0 references the array, assuming multiple input files
  • $1 references the first file
  • $2 references the second file
  • $3 references the third file, etc.

If only one file is passed in, the original value is available as $0.

As an example, if you want to union together all Features in a FeatureCollection and merge all of their properties, you could do:

gq 'union | feature | .properties = ($0.features | map(.properties) | add)' feature_collection.json

Try in the gq Playground