mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-04-26 15:13:56 +00:00
[jq/en] Fix typos (#5237)
This commit is contained in:
parent
26b5b3a747
commit
5a91556483
23
jq.md
23
jq.md
@ -3,6 +3,7 @@ category: tool
|
|||||||
name: jq
|
name: jq
|
||||||
contributors:
|
contributors:
|
||||||
- ["Jack Kuan", "https://github.com/kjkuan"]
|
- ["Jack Kuan", "https://github.com/kjkuan"]
|
||||||
|
- ["Azeem Sajid", "https://github.com/iamazeem"]
|
||||||
filename: learnjq.sh
|
filename: learnjq.sh
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -161,7 +162,7 @@ jq -rn '"1 + 2 = \(1+2)"'
|
|||||||
|
|
||||||
|
|
||||||
# The `-r` option is most useful for generating text outputs to be processed
|
# The `-r` option is most useful for generating text outputs to be processed
|
||||||
# down in a shell pipeline, especially when combined with an intepolated
|
# down in a shell pipeline, especially when combined with an interpolated
|
||||||
# string that is prefixed the `@sh` prefix operator.
|
# string that is prefixed the `@sh` prefix operator.
|
||||||
#
|
#
|
||||||
# The `@sh` operator escapes the outputs of `\(...)` inside a string with
|
# The `@sh` operator escapes the outputs of `\(...)` inside a string with
|
||||||
@ -252,7 +253,7 @@ jq -n '[2*3, 8-1, 16/2], {("tw" + "o"): (1 + 1)}'
|
|||||||
#
|
#
|
||||||
jq -n '{ key_1: "value1" }'
|
jq -n '{ key_1: "value1" }'
|
||||||
|
|
||||||
# If a JSON object's key's value is ommited, it is looked up in the current
|
# If a JSON object's key's value is omitted, it is looked up in the current
|
||||||
# input using the key: (see next example for the meaning of `... | ...`)
|
# input using the key: (see next example for the meaning of `... | ...`)
|
||||||
#
|
#
|
||||||
jq -n '{c: 3} | {a: 1, "b", c}'
|
jq -n '{c: 3} | {a: 1, "b", c}'
|
||||||
@ -384,7 +385,7 @@ jq -n '"abc" | .name? // "unknown"' # => "unknown"
|
|||||||
|
|
||||||
|
|
||||||
# Strings and arrays can be sliced with the same syntax (`[i:j]`, but no
|
# Strings and arrays can be sliced with the same syntax (`[i:j]`, but no
|
||||||
# steppings) and semantic as found in the Python programming language:
|
# stepping) and semantic as found in the Python programming language:
|
||||||
#
|
#
|
||||||
# 0 1 2 3 4 5 ... infinite
|
# 0 1 2 3 4 5 ... infinite
|
||||||
# array = ["a", "b", "c", "d"]
|
# array = ["a", "b", "c", "d"]
|
||||||
@ -397,7 +398,7 @@ jq -n '["Peter", "Jerry", "Tom"][:1+1]' # => ["Peter", "Jerry"]
|
|||||||
jq -n '["Peter", "Jerry", "Tom"][1:99]' # => ["Jerry", "Tom"]
|
jq -n '["Peter", "Jerry", "Tom"][1:99]' # => ["Jerry", "Tom"]
|
||||||
|
|
||||||
|
|
||||||
# If the lookup index or key is ommited then jq iterates through
|
# If the lookup index or key is omitted then jq iterates through
|
||||||
# the collection, generating one output value from each iteration.
|
# the collection, generating one output value from each iteration.
|
||||||
#
|
#
|
||||||
# These examples produce the same outputs.
|
# These examples produce the same outputs.
|
||||||
@ -481,7 +482,7 @@ jq -n '1, 2, 3, 4, 5 | select(. % 2 != 0)' # NOTE: % gives the remainder.
|
|||||||
|
|
||||||
|
|
||||||
# Function arguments in jq are passed with call-by-name semantic, which
|
# Function arguments in jq are passed with call-by-name semantic, which
|
||||||
# means, an argument is not evaulated at call site, but instead, is
|
# means, an argument is not evaluated at call site, but instead, is
|
||||||
# treated as a lambda expression with the calling context of the call
|
# treated as a lambda expression with the calling context of the call
|
||||||
# site as its scope for variable and function references used in the
|
# site as its scope for variable and function references used in the
|
||||||
# expression.
|
# expression.
|
||||||
@ -684,7 +685,7 @@ jq -n '[{a: 1, b: {c: 3}}, {b: 2, c: 4}] | add'
|
|||||||
|
|
||||||
|
|
||||||
# jq provides a special syntax for writing an expression that reduces
|
# jq provides a special syntax for writing an expression that reduces
|
||||||
# the outputs generated by a given expresion to a single value.
|
# the outputs generated by a given expression to a single value.
|
||||||
# It has this form:
|
# It has this form:
|
||||||
#
|
#
|
||||||
# reduce outputs_expr as $var (initial_value; reduction_expr)
|
# reduce outputs_expr as $var (initial_value; reduction_expr)
|
||||||
@ -789,7 +790,7 @@ EOF
|
|||||||
# c's total is 12
|
# c's total is 12
|
||||||
|
|
||||||
|
|
||||||
# jq supports destructing during varible binding. This lets you extract values
|
# jq supports destructing during variable binding. This lets you extract values
|
||||||
# from an array or an object and bind them to variables.
|
# from an array or an object and bind them to variables.
|
||||||
#
|
#
|
||||||
jq -n '[range(5)] | . as [$first, $second] | $second'
|
jq -n '[range(5)] | . as [$first, $second] | $second'
|
||||||
@ -822,7 +823,7 @@ jq -n '{ name: "Tom", numbers: [1, 2, 3], age: 32}
|
|||||||
jq -n '.a = 1 | .b = .a + 1' # => {"a": 1, "b": 2}
|
jq -n '.a = 1 | .b = .a + 1' # => {"a": 1, "b": 2}
|
||||||
|
|
||||||
# Note that input is `null` due to `jq -n`, so `.` is `null` in the first
|
# Note that input is `null` due to `jq -n`, so `.` is `null` in the first
|
||||||
# filter, and assiging to a key under `null` turns it into an object with
|
# filter, and assigning to a key under `null` turns it into an object with
|
||||||
# the key. The same input (now an object) then gets piped to the next filter,
|
# the key. The same input (now an object) then gets piped to the next filter,
|
||||||
# which then sets the `b` key to the value of the `a` key plus `1`, which is `2`.
|
# which then sets the `b` key to the value of the `a` key plus `1`, which is `2`.
|
||||||
#
|
#
|
||||||
@ -885,16 +886,16 @@ jq -n '
|
|||||||
# Output:
|
# Output:
|
||||||
# 9
|
# 9
|
||||||
|
|
||||||
# Some notes about function definitons:
|
# Some notes about function definitions:
|
||||||
#
|
#
|
||||||
# - Functions are usually defined at the beginning, so that they are available
|
# - Functions are usually defined at the beginning, so that they are available
|
||||||
# to the rest of the jq program.
|
# to the rest of the jq program.
|
||||||
#
|
#
|
||||||
# - Each function definion should end with a `;` (semicolon).
|
# - Each function definition should end with a `;` (semicolon).
|
||||||
#
|
#
|
||||||
# - It's also possible to define a function within another, though it's not shown here.
|
# - It's also possible to define a function within another, though it's not shown here.
|
||||||
#
|
#
|
||||||
# - Function parameters are separated by `;` (semicolor). This is consistent with
|
# - Function parameters are separated by `;` (semicolon). This is consistent with
|
||||||
# passing multiple arguments when calling a function.
|
# passing multiple arguments when calling a function.
|
||||||
#
|
#
|
||||||
# - A function can call itself; in fact, jq has TCO (Tail Call Optimization).
|
# - A function can call itself; in fact, jq has TCO (Tail Call Optimization).
|
||||||
|
Loading…
Reference in New Issue
Block a user