manual.yml (jq-1.5) | : | manual.yml (jq-1.6) | ||
---|---|---|---|---|
skipping to change at line 131 | skipping to change at line 131 | |||
Don't read any input at all! Instead, the filter is run once | Don't read any input at all! Instead, the filter is run once | |||
using `null` as the input. This is useful when using jq as a | using `null` as the input. This is useful when using jq as a | |||
simple calculator or to construct JSON data from scratch. | simple calculator or to construct JSON data from scratch. | |||
* `--compact-output` / `-c`: | * `--compact-output` / `-c`: | |||
By default, jq pretty-prints JSON output. Using this option | By default, jq pretty-prints JSON output. Using this option | |||
will result in more compact output by instead putting each | will result in more compact output by instead putting each | |||
JSON object on a single line. | JSON object on a single line. | |||
* `--colour-output` / `-C` and `--monochrome-output` / `-M`: | * `--color-output` / `-C` and `--monochrome-output` / `-M`: | |||
By default, jq outputs colored JSON if writing to a | By default, jq outputs colored JSON if writing to a | |||
terminal. You can force it to produce color even if writing to | terminal. You can force it to produce color even if writing to | |||
a pipe or a file using `-C`, and disable color with `-M`. | a pipe or a file using `-C`, and disable color with `-M`. | |||
* `--ascii-output` / `-a`: | * `--ascii-output` / `-a`: | |||
jq usually outputs non-ASCII Unicode codepoints as UTF-8, even | jq usually outputs non-ASCII Unicode codepoints as UTF-8, even | |||
if the input specified them as escape sequences (like | if the input specified them as escape sequences (like | |||
"\u03bc"). Using this option, you can force jq to produce pure | "\u03bc"). Using this option, you can force jq to produce pure | |||
skipping to change at line 629 | skipping to change at line 629 | |||
output: ['[false, true]'] | output: ['[false, true]'] | |||
- title: "`del`" | - title: "`del`" | |||
body: | | body: | | |||
The builtin function `del` removes a key and its corresponding | The builtin function `del` removes a key and its corresponding | |||
value from an object. | value from an object. | |||
examples: | examples: | |||
- program: 'del(.foo)' | - program: 'del(.foo)' | |||
input: '[{"foo": 42, "bar": 9001, "baz": 42}]' | input: '{"foo": 42, "bar": 9001, "baz": 42}' | |||
output: ['{"bar": 9001, "baz": 42}'] | output: ['{"bar": 9001, "baz": 42}'] | |||
- program: 'del(.[1, 2])' | - program: 'del(.[1, 2])' | |||
input: '[["foo", "bar", "baz"]]' | input: '["foo", "bar", "baz"]' | |||
output: ['["foo"]'] | output: ['["foo"]'] | |||
- title: "`to_entries`, `from_entries`, `with_entries`" | - title: "`to_entries`, `from_entries`, `with_entries`" | |||
body: | | body: | | |||
These functions convert between an object and an array of | These functions convert between an object and an array of | |||
key-value pairs. If `to_entries` is passed an object, then | key-value pairs. If `to_entries` is passed an object, then | |||
for each `k: v` entry in the input, the output array | for each `k: v` entry in the input, the output array | |||
includes `{"key": k, "value": v}`. | includes `{"key": k, "value": v}`. | |||
skipping to change at line 768 | skipping to change at line 768 | |||
input: '[1, 2, 3]' | input: '[1, 2, 3]' | |||
output: [6] | output: [6] | |||
- program: add | - program: add | |||
input: '[]' | input: '[]' | |||
output: ["null"] | output: ["null"] | |||
- title: "`any`" | - title: "`any`" | |||
body: | | body: | | |||
The filter `any` takes as input an array of boolean values, | The filter `any` takes as input an array of boolean values, | |||
and produces `true` as output if any of the the elements of | and produces `true` as output if any of the elements of | |||
the array is `true`. | the array are `true`. | |||
If the input is an empty array, `any` returns `false`. | If the input is an empty array, `any` returns `false`. | |||
examples: | examples: | |||
- program: any | - program: any | |||
input: '[true, false]' | input: '[true, false]' | |||
output: ["true"] | output: ["true"] | |||
- program: any | - program: any | |||
input: '[false, false]' | input: '[false, false]' | |||
output: ["false"] | output: ["false"] | |||
- program: any | - program: any | |||
input: '[]' | input: '[]' | |||
output: ["false"] | output: ["false"] | |||
- title: "`all`" | - title: "`all`" | |||
body: | | body: | | |||
The filter `all` takes as input an array of boolean values, | The filter `all` takes as input an array of boolean values, | |||
and produces `true` as output if all of the the elements of | and produces `true` as output if all of the elements of | |||
the array are `true`. | the array are `true`. | |||
If the input is an empty array, `all` returns `true`. | If the input is an empty array, `all` returns `true`. | |||
examples: | examples: | |||
- program: all | - program: all | |||
input: '[true, false]' | input: '[true, false]' | |||
output: ["false"] | output: ["false"] | |||
- program: all | - program: all | |||
input: '[true, true]' | input: '[true, true]' | |||
skipping to change at line 968 | skipping to change at line 968 | |||
elqements with a duplicate `.foo` field removed. Think of it as making | elqements with a duplicate `.foo` field removed. Think of it as making | |||
an array by taking one element out of every group produced by | an array by taking one element out of every group produced by | |||
`group_by`. | `group_by`. | |||
examples: | examples: | |||
- program: 'unique_by(.foo)' | - program: 'unique_by(.foo)' | |||
input: '[{"foo": 1, "bar": 2}, {"foo": 1, "bar": 3}, {"foo": 4, "bar ": 5}]' | input: '[{"foo": 1, "bar": 2}, {"foo": 1, "bar": 3}, {"foo": 4, "bar ": 5}]' | |||
output: ['[{"foo": 1, "bar": 2}, {"foo": 4, "bar": 5}]'] | output: ['[{"foo": 1, "bar": 2}, {"foo": 4, "bar": 5}]'] | |||
- program: 'unique_by(length)' | - program: 'unique_by(length)' | |||
input: '["chunky", "bacon", "kitten", "cicada", "asparagus"]' | input: '["chunky", "bacon", "kitten", "cicada", "asparagus"]' | |||
output: ['["chunky", "bacon", "asparagus"]'] | output: ['["bacon", "chunky", "asparagus"]'] | |||
- title: "`reverse`" | - title: "`reverse`" | |||
body: | | body: | | |||
This function reverses an array. | This function reverses an array. | |||
examples: | examples: | |||
- program: 'reverse' | - program: 'reverse' | |||
input: '[1,2,3,4]' | input: '[1,2,3,4]' | |||
output: ['[4,3,2,1]'] | output: ['[4,3,2,1]'] | |||
skipping to change at line 1038 | skipping to change at line 1038 | |||
- title: "`index(s)`, `rindex(s)`" | - title: "`index(s)`, `rindex(s)`" | |||
body: | | body: | | |||
Outputs the index of the first (`index`) or last (`rindex`) | Outputs the index of the first (`index`) or last (`rindex`) | |||
occurrence of `s` in the input. | occurrence of `s` in the input. | |||
examples: | examples: | |||
- program: 'index(", ")' | - program: 'index(", ")' | |||
input: '"a,b, cd, efg, hijk"' | input: '"a,b, cd, efg, hijk"' | |||
output: ['3'] | output: ['3'] | |||
- program: 'rindex(", ")]' | - program: 'rindex(", ")' | |||
input: '"a,b, cd, efg, hijk"' | input: '"a,b, cd, efg, hijk"' | |||
output: ['12'] | output: ['12'] | |||
- title: "`startswith`" | - title: "`startswith`" | |||
body: | | body: | | |||
Outputs `true` if . starts with the given string argument. | Outputs `true` if . starts with the given string argument. | |||
examples: | examples: | |||
- program: '[.[]|startswith("foo")]' | - program: '[.[]|startswith("foo")]' | |||
skipping to change at line 1060 | skipping to change at line 1060 | |||
output: ['[false, true, false, true, false]'] | output: ['[false, true, false, true, false]'] | |||
- title: "`endswith`" | - title: "`endswith`" | |||
body: | | body: | | |||
Outputs `true` if . ends with the given string argument. | Outputs `true` if . ends with the given string argument. | |||
examples: | examples: | |||
- program: '[.[]|endswith("foo")]' | - program: '[.[]|endswith("foo")]' | |||
input: '["foobar", "barfoo"]' | input: '["foobar", "barfoo"]' | |||
output: ['[false, true, true, false, false]'] | output: ['[false, true]'] | |||
- title: "`ltrimstr`" | - title: "`ltrimstr`" | |||
body: | | body: | | |||
Outputs its input with the given prefix string removed, if it | Outputs its input with the given prefix string removed, if it | |||
starts with it. | starts with it. | |||
examples: | examples: | |||
- program: '[.[]|ltrimstr("foo")]' | - program: '[.[]|ltrimstr("foo")]' | |||
input: '["fo", "foo", "barfoo", "foobar", "afoo"]' | input: '["fo", "foo", "barfoo", "foobar", "afoo"]' | |||
skipping to change at line 1314 | skipping to change at line 1314 | |||
as `C` otherwise. | as `C` otherwise. | |||
Checking for false or null is a simpler notion of | Checking for false or null is a simpler notion of | |||
"truthiness" than is found in Javascript or Python, but it | "truthiness" than is found in Javascript or Python, but it | |||
means that you'll sometimes have to be more explicit about | means that you'll sometimes have to be more explicit about | |||
the condition you want: you can't test whether, e.g. a | the condition you want: you can't test whether, e.g. a | |||
string is empty using `if .name then A else B end`, you'll | string is empty using `if .name then A else B end`, you'll | |||
need something more like `if (.name | length) > 0 then A else | need something more like `if (.name | length) > 0 then A else | |||
B end` instead. | B end` instead. | |||
If the condition A produces multiple results, it is | If the condition `A` produces multiple results, then `B` is evaluated | |||
considered "true" if any of those results is not false or | once for each result that is not false or null, and `C` is evaluated | |||
null. If it produces zero results, it's considered false. | once for each false or null. | |||
More cases can be added to an if using `elif A then B` syntax. | More cases can be added to an if using `elif A then B` syntax. | |||
examples: | examples: | |||
- program: |- | - program: |- | |||
if . == 0 then | if . == 0 then | |||
"zero" | "zero" | |||
elif . == 1 then | elif . == 1 then | |||
"one" | "one" | |||
else | else | |||
End of changes. 9 change blocks. | ||||
12 lines changed or deleted | 12 lines changed or added |