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]
but
echo "[1, 2, 3]" | gq 'assert(length == 2, "array length must be 2")'
returns
gq: array length must be 2
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}}
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}
}
but given invalid GeoJSON
{
"a": 1
}
validate returns
gq: Invalid GeoJSON structure: missing field `type`