@@ -708,29 +708,25 @@ sections:
708
708
input : ' [1,2,3]'
709
709
output : ['[2,3,4]']
710
710
711
- - title : " `paths`"
711
+ - title : " `paths`, `paths(node_filter)`, `leaf_paths` "
712
712
body : |
713
713
714
- Outputs the paths to all the elements in its input (except it
715
- does not output the empty list, representing . itself).
716
-
717
- `paths` is equivalent to
718
-
719
- def paths: path(recurse(if (type|. == "array" or . == "object") then .[] else empty end))|select(length > 0);
714
+ `paths` outputs the paths to all the elements in its input
715
+ (except it does not output the empty list, representing .
716
+ itself).
717
+
718
+ `paths(f)` outputs the paths to any values for which `f` is true.
719
+ That is, `paths(numbers)` outputs the paths to all numeric
720
+ values.
720
721
722
+ `leaf_paths` is an alias of `paths(scalars)`; `leaf_paths` is
723
+ *deprecated* and will be removed in the next major release.
724
+
721
725
examples :
722
726
- program : ' [paths]'
723
727
input : ' [1,[[],{"a":2}]]'
724
728
output : ['[[0],[1],[1,0],[1,1],[1,1,"a"]]']
725
-
726
- - title : " `leaf_paths`"
727
- body : |
728
-
729
- Outputs the paths to all the leaves (non-array, non-object
730
- elements) in its input.
731
-
732
- examples :
733
- - program : ' [leaf_paths]'
729
+ - program : ' [paths(scalars)]'
734
730
input : ' [1,[[],{"a":2}]]'
735
731
output : ['[[0],[1,1,"a"]]']
736
732
@@ -818,13 +814,15 @@ sections:
818
814
input : ' [{"foo": "bar"}, [{"foo": "baz"}]]'
819
815
output : ['[{"foo": "bar"}, {"foo": "baz"}]']
820
816
821
- - title : " `range`"
817
+ - title : " `range(upto), `range(from;upto) `"
822
818
body : |
823
819
824
820
The `range` function produces a range of numbers. `range(4;10)`
825
821
produces 6 numbers, from 4 (inclusive) to 10 (exclusive). The numbers
826
822
are produced as separate outputs. Use `[range(4;10)]` to get a range as
827
823
an array.
824
+
825
+ Its first argument can be omitted; it defaults to zero.
828
826
829
827
examples :
830
828
- program : ' range(2;4)'
@@ -833,6 +831,9 @@ sections:
833
831
- program : ' [range(2;4)]'
834
832
input : ' null'
835
833
output : ['[2,3]']
834
+ - program : ' [range(4)]'
835
+ input : ' null'
836
+ output : ['[0,1,2,3]']
836
837
837
838
- title : " `floor`"
838
839
body : |
@@ -890,7 +891,7 @@ sections:
890
891
input : ' [0, false, [], {}, null, "hello"]'
891
892
output : ['["number", "boolean", "array", "object", "null", "string"]']
892
893
893
- - title : " `sort, sort_by`"
894
+ - title : " `sort, sort(path_expression), sort_by(path_expression) `"
894
895
body : |
895
896
896
897
The `sort` functions sorts its input, which must be an
@@ -909,82 +910,90 @@ sections:
909
910
sorted order), and if their keys are equal then the values
910
911
are compared key by key.
911
912
912
- `sort_by` may be used to sort by a particular field of an
913
- object, or by applying any jq filter. `sort_by(foo)`
914
- compares two elements by comparing the result of `foo` on
915
- each element.
913
+ `sort` may be used to sort by a particular field of an
914
+ object, or by applying any jq filter.
915
+
916
+ `sort(foo)` compares two elements by comparing the result of
917
+ `foo` on each element.
918
+
919
+ `sort_by(foo)` is an alias of `sort(foo)`; `sort_by()` is
920
+ *deprecated* and will be removed in the next major release.
916
921
917
922
examples :
918
923
- program : ' sort'
919
924
input : ' [8,3,null,6]'
920
925
output : ['[null,3,6,8]']
921
- - program : ' sort_by (.foo)'
926
+ - program : ' sort (.foo)'
922
927
input : ' [{"foo":4, "bar":10}, {"foo":3, "bar":100}, {"foo":2, "bar":1}]'
923
928
output : ['[{"foo":2, "bar":1}, {"foo":3, "bar":100}, {"foo":4, "bar":10}]']
924
929
925
- - title : " `group_by`"
930
+ - title : " `group(path_expression)`, ` group_by(path_expression) `"
926
931
body : |
927
932
928
- `group_by (.foo)` takes as input an array, groups the
933
+ `group (.foo)` takes as input an array, groups the
929
934
elements having the same `.foo` field into separate arrays,
930
935
and produces all of these arrays as elements of a larger
931
936
array, sorted by the value of the `.foo` field.
932
937
933
938
Any jq expression, not just a field access, may be used in
934
939
place of `.foo`. The sorting order is the same as described
935
940
in the `sort` function above.
936
-
941
+
942
+ `group_by(foo)` is an alias of `group(foo)`; `group_by()` is
943
+ *deprecated* and will be removed in the next major release.
944
+
937
945
examples :
938
- - program : ' group_by (.foo)'
946
+ - program : ' group (.foo)'
939
947
input : ' [{"foo":1, "bar":10}, {"foo":3, "bar":100}, {"foo":1, "bar":1}]'
940
948
output : ['[[{"foo":1, "bar":10}, {"foo":1, "bar":1}], [{"foo":3, "bar":100}]]']
941
949
942
- - title : " `min`, `max`, `min_by`, `max_by`"
950
+ - title : " `min`, `max`, `min(path_exp)`, `max(path_exp)`, ` min_by(path_exp) `, `max_by(path_exp) `"
943
951
body : |
944
952
945
- Find the minimum or maximum element of the input array. The
946
- `_by` versions allow you to specify a particular field or
947
- property to examine, e.g. `min_by(.foo)` finds the object
953
+ Find the minimum or maximum element of the input array.
954
+ This filter accepts an optional argument that
955
+ allows you to specify a particular field or
956
+ property to examine, e.g. `min(.foo)` finds the object
948
957
with the smallest `foo` field.
958
+
959
+ For legacy reasons, `min_by(.foo)` and `max_by(.foo)` exist as
960
+ aliases for `min(.foo)` and `max(.foo)`. These aliases are
961
+ considered *deprecated* and will be removed in the next major
962
+ release.
949
963
950
964
examples :
951
965
- program : ' min'
952
966
input : ' [5,4,2,7]'
953
967
output : ['2']
954
- - program : ' max_by (.foo)'
968
+ - program : ' max (.foo)'
955
969
input : ' [{"foo":1, "bar":14}, {"foo":2, "bar":3}]'
956
970
output : ['{"foo":2, "bar":3}']
957
971
958
- - title : " `unique`"
972
+ - title : " `unique`, `unique(path_exp)`, `unique_by(path_exp)` "
959
973
body : |
960
974
961
975
The `unique` function takes as input an array and produces
962
976
an array of the same elements, in sorted order, with
963
- duplicates removed.
977
+ duplicates removed. If an optional argument is passed, it
978
+ will keep only one element for each value obtained by applying
979
+ the argument. Think of it as making an array by taking one
980
+ element out of every group produced by `group`.
981
+
982
+ For legacy reasons, `unique_by(.foo)` exists as an alias for
983
+ `unique(.foo)`. This alias is considered *deprecated* and will
984
+ be removed in the next major release.
964
985
965
986
examples :
966
987
- program : ' unique'
967
988
input : ' [1,2,5,3,5,3,1,3]'
968
989
output : ['[1,2,3,5]']
969
-
970
- - title : " `unique_by`"
971
- body : |
972
-
973
- The `unique_by(.foo)` function takes as input an array and produces
974
- an array of the same elements, in sorted order, with
975
- elqements with a duplicate `.foo` field removed. Think of it as making
976
- an array by taking one element out of every group produced by
977
- `group_by`.
978
-
979
- examples :
980
- - program : ' unique_by(.foo)'
990
+ - program : ' unique(.foo)'
981
991
input : ' [{"foo": 1, "bar": 2}, {"foo": 1, "bar": 3}, {"foo": 4, "bar": 5}]'
982
992
output : ['[{"foo": 1, "bar": 2}, {"foo": 4, "bar": 5}]']
983
- - program : ' unique_by (length)'
993
+ - program : ' unique (length)'
984
994
input : ' ["chunky", "bacon", "kitten", "cicada", "asparagus"]'
985
995
output : ['["chunky", "bacon", "asparagus"]']
986
996
987
-
988
997
- title : " `reverse`"
989
998
body : |
990
999
@@ -1144,10 +1153,10 @@ sections:
1144
1153
output : ['"a, b,c,d, e"']
1145
1154
1146
1155
1147
- - title : " `recurse`"
1156
+ - title : " `recurse(f)`, `recurse`, `recurse_down `"
1148
1157
body : |
1149
1158
1150
- The `recurse` function allows you to search through a
1159
+ The `recurse(f) ` function allows you to search through a
1151
1160
recursive structure, and extract interesting data from all
1152
1161
levels. Suppose your input represents a filesystem:
1153
1162
@@ -1165,6 +1174,13 @@ sections:
1165
1174
with:
1166
1175
1167
1176
recurse(.children[]) | .name
1177
+
1178
+ When called without an argument, `recurse` is equivalent to
1179
+ `recurse(.[]?)`.
1180
+
1181
+ For legacy reasons, `recurse_down` exists as an alias to
1182
+ calling `recurse` without arguments. This alias is considered
1183
+ *deprecated* and will be removed in the next major release.
1168
1184
1169
1185
examples :
1170
1186
- program : ' recurse(.foo[])'
@@ -1174,20 +1190,21 @@ sections:
1174
1190
- ' {"foo":[]}'
1175
1191
- ' {"foo":[{"foo":[]}]}'
1176
1192
- ' {"foo":[]}'
1177
-
1178
- - title : " `recurse_down`"
1179
- body : |
1180
-
1181
- A quieter version of `recurse(.[])`, equivalent to:
1182
-
1183
- def recurse_down: recurse(.[]?);
1193
+ - program : ' recurse'
1194
+ input : ' {"a":0,"b":[1]}'
1195
+ output :
1196
+ - ' 0'
1197
+ - ' [1]'
1198
+ - ' 1'
1184
1199
1185
1200
- title : " `..`"
1186
1201
body : |
1187
1202
1188
- Short-hand for `recurse_down`. This is intended to resemble
1189
- the XPath `//` operator. Note that `..a` does not work; use
1190
- `..|a` instead.
1203
+ Short-hand for `recurse` without arguments. This is intended
1204
+ to resemble the XPath `//` operator. Note that `..a` does not
1205
+ work; use `..|a` instead. In the example below we use
1206
+ `..|.a?` to find all the values of object keys "a" in any
1207
+ object found "below" `.`.
1191
1208
1192
1209
examples :
1193
1210
- program : ' ..|.a?'
0 commit comments