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

Miscellaneous

assert

Make an assertion on the current state of the program, returning the original JSON value unmodified if the assertion passes.

Examples

echo "[1, 2, 3]" | gq 'assert(length == 3, "array length must be 3")'

returns

[1, 2, 3]

Try in the gq Playground

but

echo "[1, 2, 3]" | gq 'assert(length == 2, "array length must be 2")'

returns

gq: array length must be 2

Try in the gq Playground

compact

Remove all non-essential whitespace from the JSON output (as opposed to the default of pretty-printing the JSON).

Example

Given:

{
  "type": "Feature",
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [
        [0, 0],
        [2, 0],
        [2, 2],
        [0, 2],
        [0, 0]
      ]
    ]
  },
  "properties": {"a": 1}
}

compact returns

{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[0, 0],[2, 0],[2, 2],[0, 2],[0, 0]]]},"properties":{"a":1}}

Try in the gq Playground

validate

Validate as GeoJSON. Returns the original JSON value unmodified if valid.

Examples

Given valid GeoJSON:

{
  "type": "Feature",
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [
        [0, 0],
        [2, 0],
        [2, 2],
        [0, 2],
        [0, 0]
      ]
    ]
  },
  "properties": {"a": 1}
}

validate returns

{
  "type": "Feature",
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [
        [0, 0],
        [2, 0],
        [2, 2],
        [0, 2],
        [0, 0]
      ]
    ]
  },
  "properties": {"a": 1}
}

Try in the gq Playground

but given invalid GeoJSON

{
  "a": 1
}

validate returns

gq: Invalid GeoJSON structure: missing field `type`

Try in the gq Playground