@@ -3,6 +3,7 @@ category: tool
3
3
name : jq
4
4
contributors :
5
5
- ["Jack Kuan", "https://github.com/kjkuan"]
6
+ - ["Azeem Sajid", "https://github.com/iamazeem"]
6
7
filename : learnjq.sh
7
8
---
8
9
@@ -161,7 +162,7 @@ jq -rn '"1 + 2 = \(1+2)"'
161
162
162
163
163
164
# The `-r` option is most useful for generating text outputs to be processed
164
- # down in a shell pipeline, especially when combined with an intepolated
165
+ # down in a shell pipeline, especially when combined with an interpolated
165
166
# string that is prefixed the `@sh` prefix operator.
166
167
#
167
168
# 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)}'
252
253
#
253
254
jq -n ' { key_1: "value1" }'
254
255
255
- # If a JSON object's key's value is ommited , it is looked up in the current
256
+ # If a JSON object's key's value is omitted , it is looked up in the current
256
257
# input using the key: (see next example for the meaning of `... | ...`)
257
258
#
258
259
jq -n ' {c: 3} | {a: 1, "b", c}'
@@ -384,7 +385,7 @@ jq -n '"abc" | .name? // "unknown"' # => "unknown"
384
385
385
386
386
387
# Strings and arrays can be sliced with the same syntax (`[i:j]`, but no
387
- # steppings ) and semantic as found in the Python programming language:
388
+ # stepping ) and semantic as found in the Python programming language:
388
389
#
389
390
# 0 1 2 3 4 5 ... infinite
390
391
# array = ["a", "b", "c", "d"]
@@ -397,7 +398,7 @@ jq -n '["Peter", "Jerry", "Tom"][:1+1]' # => ["Peter", "Jerry"]
397
398
jq -n ' ["Peter", "Jerry", "Tom"][1:99]' # => ["Jerry", "Tom"]
398
399
399
400
400
- # If the lookup index or key is ommited then jq iterates through
401
+ # If the lookup index or key is omitted then jq iterates through
401
402
# the collection, generating one output value from each iteration.
402
403
#
403
404
# These examples produce the same outputs.
@@ -481,7 +482,7 @@ jq -n '1, 2, 3, 4, 5 | select(. % 2 != 0)' # NOTE: % gives the remainder.
481
482
482
483
483
484
# Function arguments in jq are passed with call-by-name semantic, which
484
- # means, an argument is not evaulated at call site, but instead, is
485
+ # means, an argument is not evaluated at call site, but instead, is
485
486
# treated as a lambda expression with the calling context of the call
486
487
# site as its scope for variable and function references used in the
487
488
# expression.
@@ -684,7 +685,7 @@ jq -n '[{a: 1, b: {c: 3}}, {b: 2, c: 4}] | add'
684
685
685
686
686
687
# jq provides a special syntax for writing an expression that reduces
687
- # the outputs generated by a given expresion to a single value.
688
+ # the outputs generated by a given expression to a single value.
688
689
# It has this form:
689
690
#
690
691
# reduce outputs_expr as $var (initial_value; reduction_expr)
789
790
# c's total is 12
790
791
791
792
792
- # jq supports destructing during varible binding. This lets you extract values
793
+ # jq supports destructing during variable binding. This lets you extract values
793
794
# from an array or an object and bind them to variables.
794
795
#
795
796
jq -n ' [range(5)] | . as [$first, $second] | $second'
@@ -822,7 +823,7 @@ jq -n '{ name: "Tom", numbers: [1, 2, 3], age: 32}
822
823
jq -n ' .a = 1 | .b = .a + 1' # => {"a": 1, "b": 2}
823
824
824
825
# Note that input is `null` due to `jq -n`, so `.` is `null` in the first
825
- # filter, and assiging to a key under `null` turns it into an object with
826
+ # filter, and assigning to a key under `null` turns it into an object with
826
827
# the key. The same input (now an object) then gets piped to the next filter,
827
828
# which then sets the `b` key to the value of the `a` key plus `1`, which is `2`.
828
829
#
@@ -885,16 +886,16 @@ jq -n '
885
886
# Output:
886
887
# 9
887
888
888
- # Some notes about function definitons :
889
+ # Some notes about function definitions :
889
890
#
890
891
# - Functions are usually defined at the beginning, so that they are available
891
892
# to the rest of the jq program.
892
893
#
893
- # - Each function definion should end with a `;` (semicolon).
894
+ # - Each function definition should end with a `;` (semicolon).
894
895
#
895
896
# - It's also possible to define a function within another, though it's not shown here.
896
897
#
897
- # - Function parameters are separated by `;` (semicolor ). This is consistent with
898
+ # - Function parameters are separated by `;` (semicolon ). This is consistent with
898
899
# passing multiple arguments when calling a function.
899
900
#
900
901
# - A function can call itself; in fact, jq has TCO (Tail Call Optimization).
0 commit comments