@port-labs/jq-node-bindings 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding.gyp +3 -3
- package/configure +8 -6
- package/deps/jq/.travis.yml +184 -35
- package/deps/jq/AUTHORS +31 -30
- package/deps/jq/COPYING +2 -2
- package/deps/jq/KEYS +8 -0
- package/deps/jq/Makefile.am +85 -70
- package/deps/jq/NEWS +5 -4
- package/deps/jq/README.md +18 -9
- package/deps/jq/appveyor.yml +53 -0
- package/deps/jq/compile-ios.sh +5 -5
- package/deps/jq/config/m4/check-math-func.m4 +7 -2
- package/deps/jq/configure.ac +130 -68
- package/deps/jq/docs/Rakefile +14 -135
- package/deps/jq/docs/Rakefile.manual +49 -0
- package/deps/jq/docs/Rakefile.website +76 -0
- package/deps/jq/docs/content/2.download/default.yml +115 -39
- package/deps/jq/docs/content/3.manual/manual.yml +641 -231
- package/deps/jq/docs/content/3.manual/v1.3/manual.yml +130 -130
- package/deps/jq/docs/content/3.manual/v1.4/manual.yml +160 -160
- package/deps/jq/docs/content/3.manual/v1.5/manual.yml +2878 -0
- package/deps/jq/docs/content/3.manual/v1.6/manual.yml +3287 -0
- package/deps/jq/docs/content/index/index.yml +28 -6
- package/deps/jq/docs/public/.htaccess +2 -2
- package/deps/jq/docs/public/css/base.scss +141 -59
- package/deps/jq/docs/public/js/manual-search.js +52 -0
- package/deps/jq/docs/site.yml +1 -10
- package/deps/jq/docs/templates/default.liquid +10 -10
- package/deps/jq/docs/templates/index.liquid +45 -32
- package/deps/jq/docs/templates/manual.liquid +67 -90
- package/deps/jq/docs/templates/shared/_footer.liquid +10 -5
- package/deps/jq/docs/templates/shared/_head.liquid +17 -12
- package/deps/jq/docs/templates/shared/_navbar.liquid +27 -0
- package/deps/jq/jq.1.prebuilt +523 -139
- package/deps/jq/modules/oniguruma/AUTHORS +1 -0
- package/deps/jq/modules/oniguruma/CMakeLists.txt +86 -0
- package/deps/jq/modules/oniguruma/COPYING +28 -0
- package/deps/jq/modules/oniguruma/ChangeLog +0 -0
- package/deps/jq/modules/oniguruma/HISTORY +2138 -0
- package/deps/jq/modules/oniguruma/Makefile.am +33 -0
- package/deps/jq/modules/oniguruma/NEWS +0 -0
- package/deps/jq/modules/oniguruma/README +189 -0
- package/deps/jq/modules/oniguruma/README.ja +195 -0
- package/deps/jq/modules/oniguruma/README.md +203 -0
- package/deps/jq/modules/oniguruma/cmake/dist.cmake +321 -0
- package/deps/jq/modules/oniguruma/compile +348 -0
- package/deps/jq/modules/oniguruma/config.guess +1754 -0
- package/deps/jq/modules/oniguruma/config.sub +1890 -0
- package/deps/jq/modules/oniguruma/configure.ac +87 -0
- package/deps/jq/modules/oniguruma/contributed/libfuzzer-onig.cpp +31 -0
- package/deps/jq/modules/oniguruma/depcomp +791 -0
- package/deps/jq/modules/oniguruma/dist.info +10 -0
- package/deps/jq/modules/oniguruma/doc/API +660 -0
- package/deps/jq/modules/oniguruma/doc/API.ja +667 -0
- package/deps/jq/modules/oniguruma/doc/FAQ +12 -0
- package/deps/jq/modules/oniguruma/doc/FAQ.ja +22 -0
- package/deps/jq/modules/oniguruma/doc/RE +436 -0
- package/deps/jq/modules/oniguruma/doc/RE.ja +448 -0
- package/deps/jq/modules/oniguruma/doc/UNICODE_PROPERTIES +698 -0
- package/deps/jq/modules/oniguruma/index.html +181 -0
- package/deps/jq/modules/oniguruma/index_ja.html +184 -0
- package/deps/jq/modules/oniguruma/install-sh +541 -0
- package/deps/jq/modules/oniguruma/m4/.whatever +0 -0
- package/deps/jq/modules/oniguruma/make_win32.bat +3 -0
- package/deps/jq/modules/oniguruma/make_win64.bat +3 -0
- package/deps/jq/modules/oniguruma/missing +215 -0
- package/deps/jq/modules/oniguruma/onig-config.in +78 -0
- package/deps/jq/modules/oniguruma/oniguruma.pc.cmake.in +13 -0
- package/deps/jq/modules/oniguruma/oniguruma.pc.in +14 -0
- package/deps/jq/modules/oniguruma/sample/CMakeLists.txt +28 -0
- package/deps/jq/modules/oniguruma/sample/Makefile.am +34 -0
- package/deps/jq/modules/oniguruma/sample/bug_fix.c +131 -0
- package/deps/jq/modules/oniguruma/sample/crnl.c +127 -0
- package/deps/jq/modules/oniguruma/sample/encode.c +308 -0
- package/deps/jq/modules/oniguruma/sample/listcap.c +110 -0
- package/deps/jq/modules/oniguruma/sample/names.c +75 -0
- package/deps/jq/modules/oniguruma/sample/posix.c +96 -0
- package/deps/jq/modules/oniguruma/sample/scan.c +88 -0
- package/deps/jq/modules/oniguruma/sample/simple.c +59 -0
- package/deps/jq/modules/oniguruma/sample/sql.c +76 -0
- package/deps/jq/modules/oniguruma/sample/syntax.c +76 -0
- package/deps/jq/modules/oniguruma/sample/user_property.c +87 -0
- package/deps/jq/modules/oniguruma/src/Makefile.am +58 -0
- package/deps/jq/modules/oniguruma/src/Makefile.windows +183 -0
- package/deps/jq/modules/oniguruma/src/ascii.c +61 -0
- package/deps/jq/modules/oniguruma/src/big5.c +190 -0
- package/deps/jq/modules/oniguruma/src/config.h.cmake.in +71 -0
- package/deps/jq/modules/oniguruma/src/config.h.win32 +84 -0
- package/deps/jq/modules/oniguruma/src/config.h.win64 +84 -0
- package/deps/jq/modules/oniguruma/src/cp1251.c +203 -0
- package/deps/jq/modules/oniguruma/src/euc_jp.c +310 -0
- package/deps/jq/modules/oniguruma/src/euc_jp_prop.c +158 -0
- package/deps/jq/modules/oniguruma/src/euc_jp_prop.gperf +27 -0
- package/deps/jq/modules/oniguruma/src/euc_kr.c +188 -0
- package/deps/jq/modules/oniguruma/src/euc_tw.c +171 -0
- package/deps/jq/modules/oniguruma/src/gb18030.c +538 -0
- package/deps/jq/modules/oniguruma/src/gperf_fold_key_conv.py +67 -0
- package/deps/jq/modules/oniguruma/src/gperf_unfold_key_conv.py +55 -0
- package/deps/jq/modules/oniguruma/src/iso8859_1.c +275 -0
- package/deps/jq/modules/oniguruma/src/iso8859_10.c +242 -0
- package/deps/jq/modules/oniguruma/src/iso8859_11.c +99 -0
- package/deps/jq/modules/oniguruma/src/iso8859_13.c +231 -0
- package/deps/jq/modules/oniguruma/src/iso8859_14.c +244 -0
- package/deps/jq/modules/oniguruma/src/iso8859_15.c +238 -0
- package/deps/jq/modules/oniguruma/src/iso8859_16.c +240 -0
- package/deps/jq/modules/oniguruma/src/iso8859_2.c +238 -0
- package/deps/jq/modules/oniguruma/src/iso8859_3.c +238 -0
- package/deps/jq/modules/oniguruma/src/iso8859_4.c +240 -0
- package/deps/jq/modules/oniguruma/src/iso8859_5.c +229 -0
- package/deps/jq/modules/oniguruma/src/iso8859_6.c +99 -0
- package/deps/jq/modules/oniguruma/src/iso8859_7.c +225 -0
- package/deps/jq/modules/oniguruma/src/iso8859_8.c +99 -0
- package/deps/jq/modules/oniguruma/src/iso8859_9.c +231 -0
- package/deps/jq/modules/oniguruma/src/koi8.c +253 -0
- package/deps/jq/modules/oniguruma/src/koi8_r.c +215 -0
- package/deps/jq/modules/oniguruma/src/make_unicode_fold.sh +22 -0
- package/deps/jq/modules/oniguruma/src/make_unicode_fold_data.py +306 -0
- package/deps/jq/modules/oniguruma/src/make_unicode_property.sh +18 -0
- package/deps/jq/modules/oniguruma/src/make_unicode_property_data.py +545 -0
- package/deps/jq/modules/oniguruma/src/mktable.c +1184 -0
- package/deps/jq/modules/oniguruma/src/onig_init.c +45 -0
- package/deps/jq/modules/oniguruma/src/oniggnu.h +85 -0
- package/deps/jq/modules/oniguruma/src/onigposix.h +169 -0
- package/deps/jq/modules/oniguruma/src/oniguruma.h +841 -0
- package/deps/jq/modules/oniguruma/src/regcomp.c +6300 -0
- package/deps/jq/modules/oniguruma/src/regenc.c +917 -0
- package/deps/jq/modules/oniguruma/src/regenc.h +243 -0
- package/deps/jq/modules/oniguruma/src/regerror.c +393 -0
- package/deps/jq/modules/oniguruma/src/regexec.c +3856 -0
- package/deps/jq/modules/oniguruma/src/regext.c +202 -0
- package/deps/jq/modules/oniguruma/src/reggnu.c +147 -0
- package/deps/jq/modules/oniguruma/src/regint.h +779 -0
- package/deps/jq/modules/oniguruma/src/regparse.c +5403 -0
- package/deps/jq/modules/oniguruma/src/regparse.h +351 -0
- package/deps/jq/modules/oniguruma/src/regposerr.c +105 -0
- package/deps/jq/modules/oniguruma/src/regposix.c +306 -0
- package/deps/jq/modules/oniguruma/src/regsyntax.c +315 -0
- package/deps/jq/modules/oniguruma/src/regtrav.c +76 -0
- package/deps/jq/modules/oniguruma/src/regversion.c +57 -0
- package/deps/jq/modules/oniguruma/src/sjis.c +341 -0
- package/deps/jq/modules/oniguruma/src/sjis_prop.c +158 -0
- package/deps/jq/modules/oniguruma/src/sjis_prop.gperf +27 -0
- package/deps/jq/modules/oniguruma/src/st.c +589 -0
- package/deps/jq/modules/oniguruma/src/st.h +68 -0
- package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold1_key.c +2250 -0
- package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold2_key.c +203 -0
- package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold3_key.c +113 -0
- package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold_data.c +1225 -0
- package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_property_data.c +24742 -0
- package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_property_data_posix.c +4846 -0
- package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_unfold_key.c +2571 -0
- package/deps/jq/modules/oniguruma/src/unicode.c +664 -0
- package/deps/jq/modules/oniguruma/src/unicode_fold1_key.c +2548 -0
- package/deps/jq/modules/oniguruma/src/unicode_fold2_key.c +203 -0
- package/deps/jq/modules/oniguruma/src/unicode_fold3_key.c +113 -0
- package/deps/jq/modules/oniguruma/src/unicode_fold_data.c +1366 -0
- package/deps/jq/modules/oniguruma/src/unicode_property_data.c +25306 -0
- package/deps/jq/modules/oniguruma/src/unicode_property_data_posix.c +4940 -0
- package/deps/jq/modules/oniguruma/src/unicode_unfold_key.c +2854 -0
- package/deps/jq/modules/oniguruma/src/utf16_be.c +235 -0
- package/deps/jq/modules/oniguruma/src/utf16_le.c +245 -0
- package/deps/jq/modules/oniguruma/src/utf32_be.c +194 -0
- package/deps/jq/modules/oniguruma/src/utf32_le.c +194 -0
- package/deps/jq/modules/oniguruma/src/utf8.c +335 -0
- package/deps/jq/modules/oniguruma/test/Makefile.am +28 -0
- package/deps/jq/modules/oniguruma/test/testc.c +874 -0
- package/deps/jq/modules/oniguruma/test/testu.c +916 -0
- package/deps/jq/modules/oniguruma/test-driver +153 -0
- package/deps/jq/modules/oniguruma/windows/testc.c +869 -0
- package/deps/jq/scripts/crosscompile +2 -1
- package/deps/jq/scripts/gen_utf8_tables.py +2 -3
- package/deps/jq/scripts/update-website +29 -0
- package/deps/jq/scripts/version +7 -2
- package/deps/jq/sig/jq-release.key +41 -0
- package/deps/jq/sig/v1.3/jq-linux-x86.asc +17 -0
- package/deps/jq/sig/v1.3/jq-linux-x86_64.asc +17 -0
- package/deps/jq/sig/v1.3/jq-osx-x86.asc +17 -0
- package/deps/jq/sig/v1.3/jq-osx-x86_64.asc +17 -0
- package/deps/jq/sig/v1.3/jq-win32.exe.asc +17 -0
- package/deps/jq/sig/v1.3/jq-win64.exe.asc +17 -0
- package/deps/jq/sig/v1.3/sha256sum.txt +6 -0
- package/deps/jq/sig/v1.4/jq-linux-x86.asc +17 -0
- package/deps/jq/sig/v1.4/jq-linux-x86_64.asc +17 -0
- package/deps/jq/sig/v1.4/jq-osx-x86.asc +17 -0
- package/deps/jq/sig/v1.4/jq-osx-x86_64.asc +17 -0
- package/deps/jq/sig/v1.4/jq-solaris11-32.asc +17 -0
- package/deps/jq/sig/v1.4/jq-solaris11-64.asc +17 -0
- package/deps/jq/sig/v1.4/jq-win32.exe.asc +17 -0
- package/deps/jq/sig/v1.4/jq-win64.exe.asc +17 -0
- package/deps/jq/sig/v1.4/sha256sum.txt +8 -0
- package/deps/jq/sig/v1.5/jq-linux32-no-oniguruma.asc +17 -0
- package/deps/jq/sig/v1.5/jq-linux32.asc +17 -0
- package/deps/jq/sig/v1.5/jq-linux64.asc +17 -0
- package/deps/jq/sig/v1.5/jq-osx-amd64.asc +17 -0
- package/deps/jq/sig/v1.5/jq-win32.exe.asc +17 -0
- package/deps/jq/sig/v1.5/jq-win64.exe.asc +17 -0
- package/deps/jq/sig/v1.5/sha256sum.txt +5 -0
- package/deps/jq/sig/v1.5rc1/jq-linux-x86_64-static.asc +17 -0
- package/deps/jq/sig/v1.5rc1/jq-win32.exe.asc +17 -0
- package/deps/jq/sig/v1.5rc1/jq-win64.exe.asc +17 -0
- package/deps/jq/sig/v1.5rc1/sha256sum.txt +3 -0
- package/deps/jq/sig/v1.5rc2/jq-linux-x86.asc +17 -0
- package/deps/jq/sig/v1.5rc2/jq-linux-x86_64.asc +17 -0
- package/deps/jq/sig/v1.5rc2/jq-osx-x86_64.asc +17 -0
- package/deps/jq/sig/v1.5rc2/jq-win32.exe.asc +17 -0
- package/deps/jq/sig/v1.5rc2/jq-win64.exe.asc +17 -0
- package/deps/jq/sig/v1.5rc2/sha256sum.txt +5 -0
- package/deps/jq/sig/v1.6/jq-linux32.asc +16 -0
- package/deps/jq/sig/v1.6/jq-linux64.asc +16 -0
- package/deps/jq/sig/v1.6/jq-osx-amd64.asc +16 -0
- package/deps/jq/sig/v1.6/jq-win32.exe.asc +16 -0
- package/deps/jq/sig/v1.6/jq-win64.exe.asc +16 -0
- package/deps/jq/sig/v1.6/sha256sum.txt +5 -0
- package/deps/jq/{builtin.c → src/builtin.c} +449 -344
- package/deps/jq/{builtin.h → src/builtin.h} +0 -0
- package/deps/jq/src/builtin.jq +311 -0
- package/deps/jq/{bytecode.c → src/bytecode.c} +0 -0
- package/deps/jq/{bytecode.h → src/bytecode.h} +0 -0
- package/deps/jq/{compile.c → src/compile.c} +213 -37
- package/deps/jq/{compile.h → src/compile.h} +7 -2
- package/deps/jq/{exec_stack.h → src/exec_stack.h} +0 -0
- package/deps/jq/{execute.c → src/execute.c} +127 -24
- package/deps/jq/{inject_errors.c → src/inject_errors.c} +0 -0
- package/deps/jq/{jq.h → src/jq.h} +13 -2
- package/deps/jq/{jq_parser.h → src/jq_parser.h} +0 -0
- package/deps/jq/{jq_test.c → src/jq_test.c} +1 -1
- package/deps/jq/{jv.c → src/jv.c} +24 -5
- package/deps/jq/{jv.h → src/jv.h} +46 -11
- package/deps/jq/{jv_alloc.c → src/jv_alloc.c} +0 -0
- package/deps/jq/{jv_alloc.h → src/jv_alloc.h} +0 -0
- package/deps/jq/{jv_aux.c → src/jv_aux.c} +38 -14
- package/deps/jq/{jv_dtoa.c → src/jv_dtoa.c} +4 -5
- package/deps/jq/{jv_dtoa.h → src/jv_dtoa.h} +0 -0
- package/deps/jq/src/jv_file.c +81 -0
- package/deps/jq/{jv_parse.c → src/jv_parse.c} +8 -2
- package/deps/jq/{jv_print.c → src/jv_print.c} +80 -27
- package/deps/jq/{jv_unicode.c → src/jv_unicode.c} +28 -4
- package/deps/jq/{jv_unicode.h → src/jv_unicode.h} +1 -0
- package/deps/jq/{jv_utf8_tables.h → src/jv_utf8_tables.h} +0 -0
- package/deps/jq/{lexer.c → src/lexer.c} +317 -292
- package/deps/jq/{lexer.h → src/lexer.h} +16 -12
- package/deps/jq/{lexer.l → src/lexer.l} +5 -4
- package/deps/jq/src/libm.h +291 -0
- package/deps/jq/{linker.c → src/linker.c} +5 -3
- package/deps/jq/{linker.h → src/linker.h} +0 -0
- package/deps/jq/{locfile.c → src/locfile.c} +1 -1
- package/deps/jq/{locfile.h → src/locfile.h} +0 -0
- package/deps/jq/{main.c → src/main.c} +202 -100
- package/deps/jq/{opcode_list.h → src/opcode_list.h} +4 -0
- package/deps/jq/{parser.c → src/parser.c} +1149 -1069
- package/deps/jq/{parser.h → src/parser.h} +28 -24
- package/deps/jq/{parser.y → src/parser.y} +108 -52
- package/deps/jq/{util.c → src/util.c} +12 -9
- package/deps/jq/{util.h → src/util.h} +0 -0
- package/deps/jq/tests/base64.test +35 -0
- package/deps/jq/tests/base64test +5 -0
- package/deps/jq/tests/jq-f-test.sh +4 -0
- package/deps/jq/tests/jq.test +305 -21
- package/deps/jq/tests/jqtest +1 -1
- package/deps/jq/tests/mantest +1 -1
- package/deps/jq/tests/onig.test +13 -0
- package/deps/jq/tests/onigtest +1 -1
- package/deps/jq/tests/optional.test +20 -0
- package/deps/jq/tests/optionaltest +5 -0
- package/deps/jq/tests/setup +7 -1
- package/deps/jq/tests/shtest +133 -29
- package/deps/jq/tests/utf8-truncate.jq +3 -0
- package/deps/jq/tests/utf8test +10 -0
- package/lib/index.js +7 -1
- package/package.json +3 -3
- package/test/santiy.test.js +24 -0
- package/deps/jq/docs/default_manpage.md +0 -22
- package/deps/jq/docs/public/bootstrap/css/bootstrap-responsive.css +0 -1058
- package/deps/jq/docs/public/bootstrap/css/bootstrap-responsive.min.css +0 -9
- package/deps/jq/docs/public/bootstrap/css/bootstrap.css +0 -5224
- package/deps/jq/docs/public/bootstrap/css/bootstrap.min.css +0 -9
- package/deps/jq/docs/public/bootstrap/img/glyphicons-halflings-white.png +0 -0
- package/deps/jq/docs/public/bootstrap/img/glyphicons-halflings.png +0 -0
- package/deps/jq/docs/public/bootstrap/js/bootstrap.js +0 -2027
- package/deps/jq/docs/public/bootstrap/js/bootstrap.min.js +0 -6
- package/deps/jq/docs/templates/shared/_header.liquid +0 -26
- package/deps/jq/jq.1.default +0 -39
- package/deps/jq/jv_file.c +0 -49
- package/deps/jq/libm.h +0 -160
- package/deps/jq/setup.sh +0 -33
- package/reports/jest-port-api.xml +0 -35
|
@@ -16,7 +16,7 @@ body: |
|
|
|
16
16
|
Filters can be combined in various ways - you can pipe the output of
|
|
17
17
|
one filter into another filter, or collect the output of a filter
|
|
18
18
|
into an array.
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
Some filters produce multiple results, for instance there's one that
|
|
21
21
|
produces all the elements of its input array. Piping that filter
|
|
22
22
|
into a second runs the second filter for each element of the
|
|
@@ -50,7 +50,7 @@ manpage_intro: |
|
|
|
50
50
|
By default, `jq` reads a stream of JSON objects (whitespace
|
|
51
51
|
separated) from `stdin`. One or more <files> may be specified, in
|
|
52
52
|
which case `jq` will read input from those instead.
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
The <options> are described in the [INVOKING JQ] section, they
|
|
55
55
|
mostly concern input and output formatting. The <filter> is written
|
|
56
56
|
in the jq language and specifies how to transform the input
|
|
@@ -68,11 +68,11 @@ manpage_epilogue: |
|
|
|
68
68
|
## AUTHOR
|
|
69
69
|
|
|
70
70
|
Stephen Dolan `<mu@netsoc.tcd.ie>`
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
sections:
|
|
73
73
|
- title: Invoking jq
|
|
74
74
|
body: |
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
jq filters run on a stream of JSON data. The input to jq is
|
|
77
77
|
parsed as a sequence of whitespace-separated JSON values which
|
|
78
78
|
are passed through the provided filter one at a time. The
|
|
@@ -98,44 +98,44 @@ sections:
|
|
|
98
98
|
Output the jq version and exit with zero.
|
|
99
99
|
|
|
100
100
|
* `--slurp`/`-s`:
|
|
101
|
-
|
|
101
|
+
|
|
102
102
|
Instead of running the filter for each JSON object in the
|
|
103
103
|
input, read the entire input stream into a large array and run
|
|
104
104
|
the filter just once.
|
|
105
105
|
|
|
106
106
|
* `--online-input`/`-I`:
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
When the top-level input value is an array produce its elements
|
|
109
109
|
instead of the array. This allows on-line processing of
|
|
110
110
|
potentially very large top-level arrays' elements.
|
|
111
|
-
|
|
111
|
+
|
|
112
112
|
* `--raw-input`/`-R`:
|
|
113
|
-
|
|
113
|
+
|
|
114
114
|
Don't parse the input as JSON. Instead, each line of text is
|
|
115
115
|
passed to the filter as a string. If combined with `--slurp`,
|
|
116
116
|
then the entire input is passed to the filter as a single long
|
|
117
117
|
string.
|
|
118
|
-
|
|
118
|
+
|
|
119
119
|
* `--null-input`/`-n`:
|
|
120
|
-
|
|
120
|
+
|
|
121
121
|
Don't read any input at all! Instead, the filter is run once
|
|
122
122
|
using `null` as the input. This is useful when using jq as a
|
|
123
123
|
simple calculator or to construct JSON data from scratch.
|
|
124
|
-
|
|
124
|
+
|
|
125
125
|
* `--compact-output` / `-c`:
|
|
126
|
-
|
|
126
|
+
|
|
127
127
|
By default, jq pretty-prints JSON output. Using this option
|
|
128
128
|
will result in more compact output by instead putting each
|
|
129
129
|
JSON object on a single line.
|
|
130
|
-
|
|
131
|
-
* `--
|
|
132
|
-
|
|
130
|
+
|
|
131
|
+
* `--color-output` / `-C` and `--monochrome-output` / `-M`:
|
|
132
|
+
|
|
133
133
|
By default, jq outputs colored JSON if writing to a
|
|
134
134
|
terminal. You can force it to produce color even if writing to
|
|
135
135
|
a pipe or a file using `-C`, and disable color with `-M`.
|
|
136
|
-
|
|
136
|
+
|
|
137
137
|
* `--ascii-output` / `-a`:
|
|
138
|
-
|
|
138
|
+
|
|
139
139
|
jq usually outputs non-ASCII Unicode codepoints as UTF-8, even
|
|
140
140
|
if the input specified them as escape sequences (like
|
|
141
141
|
"\u03bc"). Using this option, you can force jq to produce pure
|
|
@@ -149,11 +149,11 @@ sections:
|
|
|
149
149
|
output elsewhere).
|
|
150
150
|
|
|
151
151
|
* `--sort-keys` / `-S`:
|
|
152
|
-
|
|
152
|
+
|
|
153
153
|
Output the fields of each object with the keys in sorted order.
|
|
154
154
|
|
|
155
155
|
* `--raw-output` / `-r`:
|
|
156
|
-
|
|
156
|
+
|
|
157
157
|
With this option, if the filter's result is a string then it
|
|
158
158
|
will be written directly to standard output rather than being
|
|
159
159
|
formatted as a JSON string with quotes. This can be useful for
|
|
@@ -191,7 +191,7 @@ sections:
|
|
|
191
191
|
entries:
|
|
192
192
|
- title: "`.`"
|
|
193
193
|
body: |
|
|
194
|
-
|
|
194
|
+
|
|
195
195
|
The absolute simplest (and least interesting) filter
|
|
196
196
|
is `.`. This is a filter that takes its input and
|
|
197
197
|
produces it unchanged as output.
|
|
@@ -207,7 +207,7 @@ sections:
|
|
|
207
207
|
|
|
208
208
|
- title: "`.foo`, `.foo.bar`"
|
|
209
209
|
body: |
|
|
210
|
-
|
|
210
|
+
|
|
211
211
|
The simplest *useful* filter is `.foo`. When given a
|
|
212
212
|
JSON object (aka dictionary or hash) as input, it produces
|
|
213
213
|
the value at the key "foo", or null if there's none present.
|
|
@@ -216,7 +216,7 @@ sections:
|
|
|
216
216
|
it with double quotes like this: `."foo$"`.
|
|
217
217
|
|
|
218
218
|
A filter of the form `.foo.bar` is equivalent to `.foo|.bar`.
|
|
219
|
-
|
|
219
|
+
|
|
220
220
|
examples:
|
|
221
221
|
- program: '.foo'
|
|
222
222
|
input: '{"foo": 42, "bar": "less interesting data"}'
|
|
@@ -230,7 +230,7 @@ sections:
|
|
|
230
230
|
|
|
231
231
|
- title: "`.foo?`"
|
|
232
232
|
body: |
|
|
233
|
-
|
|
233
|
+
|
|
234
234
|
Just like `.foo`, but does not output even an error when `.`
|
|
235
235
|
is not an array or an object.
|
|
236
236
|
|
|
@@ -250,7 +250,7 @@ sections:
|
|
|
250
250
|
|
|
251
251
|
- title: "`.[<string>]`, `.[2]`, `.[10:15]`"
|
|
252
252
|
body: |
|
|
253
|
-
|
|
253
|
+
|
|
254
254
|
You can also look up fields of an object using syntax like
|
|
255
255
|
`.["foo"]` (.foo above is a shorthand version of this). This
|
|
256
256
|
one works for arrays as well, if the key is an
|
|
@@ -285,7 +285,7 @@ sections:
|
|
|
285
285
|
- program: '.[2:4]'
|
|
286
286
|
input: '"abcdefghi"'
|
|
287
287
|
output: ['"cd"']
|
|
288
|
-
|
|
288
|
+
|
|
289
289
|
- program: '.[:3]'
|
|
290
290
|
input: '["a","b","c","d","e"]'
|
|
291
291
|
output: ['["a", "b", "c"]']
|
|
@@ -296,7 +296,7 @@ sections:
|
|
|
296
296
|
|
|
297
297
|
- title: "`.[]`"
|
|
298
298
|
body: |
|
|
299
|
-
|
|
299
|
+
|
|
300
300
|
If you use the `.[index]` syntax, but omit the index
|
|
301
301
|
entirely, it will return *all* of the elements of an
|
|
302
302
|
array. Running `.[]` with the input `[1,2,3]` will produce the
|
|
@@ -323,13 +323,13 @@ sections:
|
|
|
323
323
|
|
|
324
324
|
- title: "`.[]?`"
|
|
325
325
|
body: |
|
|
326
|
-
|
|
326
|
+
|
|
327
327
|
Like `.[]`, but no errors will be output if . is not an array
|
|
328
328
|
or object.
|
|
329
329
|
|
|
330
330
|
- title: "`,`"
|
|
331
331
|
body: |
|
|
332
|
-
|
|
332
|
+
|
|
333
333
|
If two filters are separated by a comma, then the
|
|
334
334
|
input will be fed into both and there will be multiple
|
|
335
335
|
outputs: first, all of the outputs produced by the left
|
|
@@ -344,18 +344,18 @@ sections:
|
|
|
344
344
|
|
|
345
345
|
- program: ".user, .projects[]"
|
|
346
346
|
input: '{"user":"stedolan", "projects": ["jq", "wikiflow"]}'
|
|
347
|
-
output: ['"stedolan"', '"jq"', '"wikiflow"']
|
|
348
|
-
|
|
347
|
+
output: ['"stedolan"', '"jq"', '"wikiflow"']
|
|
348
|
+
|
|
349
349
|
- program: '.[4,2]'
|
|
350
350
|
input: '["a","b","c","d","e"]'
|
|
351
351
|
output: ['"e"', '"c"']
|
|
352
|
-
|
|
352
|
+
|
|
353
353
|
- title: "`|`"
|
|
354
354
|
body: |
|
|
355
355
|
The | operator combines two filters by feeding the output(s) of
|
|
356
356
|
the one on the left into the input of the one on the right. It's
|
|
357
357
|
pretty much the same as the Unix shell's pipe, if you're used to
|
|
358
|
-
that.
|
|
358
|
+
that.
|
|
359
359
|
|
|
360
360
|
If the one on the left produces multiple results, the one on
|
|
361
361
|
the right will be run for each of those results. So, the
|
|
@@ -369,7 +369,7 @@ sections:
|
|
|
369
369
|
|
|
370
370
|
- title: Types and Values
|
|
371
371
|
body: |
|
|
372
|
-
|
|
372
|
+
|
|
373
373
|
jq supports the same set of datatypes as JSON - numbers,
|
|
374
374
|
strings, booleans, arrays, objects (which in JSON-speak are
|
|
375
375
|
hashes with only string keys), and "null".
|
|
@@ -383,7 +383,7 @@ sections:
|
|
|
383
383
|
entries:
|
|
384
384
|
- title: Array construction - `[]`
|
|
385
385
|
body: |
|
|
386
|
-
|
|
386
|
+
|
|
387
387
|
As in JSON, `[]` is used to construct arrays, as in
|
|
388
388
|
`[1,2,3]`. The elements of the arrays can be any jq
|
|
389
389
|
expression. All of the results produced by all of the
|
|
@@ -391,7 +391,7 @@ sections:
|
|
|
391
391
|
to construct an array out of a known quantity of values (as
|
|
392
392
|
in `[.foo, .bar, .baz]`) or to "collect" all the results of a
|
|
393
393
|
filter into an array (as in `[.items[].name]`)
|
|
394
|
-
|
|
394
|
+
|
|
395
395
|
Once you understand the "," operator, you can look at jq's array
|
|
396
396
|
syntax in a different light: the expression `[1,2,3]` is not using a
|
|
397
397
|
built-in syntax for comma-separated arrays, but is instead applying
|
|
@@ -411,49 +411,49 @@ sections:
|
|
|
411
411
|
|
|
412
412
|
Like JSON, `{}` is for constructing objects (aka
|
|
413
413
|
dictionaries or hashes), as in: `{"a": 42, "b": 17}`.
|
|
414
|
-
|
|
414
|
+
|
|
415
415
|
If the keys are "sensible" (all alphabetic characters), then
|
|
416
416
|
the quotes can be left off. The value can be any expression
|
|
417
417
|
(although you may need to wrap it in parentheses if it's a
|
|
418
418
|
complicated one), which gets applied to the {} expression's
|
|
419
419
|
input (remember, all filters have an input and an
|
|
420
420
|
output).
|
|
421
|
-
|
|
421
|
+
|
|
422
422
|
{foo: .bar}
|
|
423
|
-
|
|
423
|
+
|
|
424
424
|
will produce the JSON object `{"foo": 42}` if given the JSON
|
|
425
425
|
object `{"bar":42, "baz":43}`. You can use this to select
|
|
426
426
|
particular fields of an object: if the input is an object
|
|
427
427
|
with "user", "title", "id", and "content" fields and you
|
|
428
428
|
just want "user" and "title", you can write
|
|
429
|
-
|
|
429
|
+
|
|
430
430
|
{user: .user, title: .title}
|
|
431
|
-
|
|
431
|
+
|
|
432
432
|
Because that's so common, there's a shortcut syntax: `{user, title}`.
|
|
433
|
-
|
|
433
|
+
|
|
434
434
|
If one of the expressions produces multiple results,
|
|
435
435
|
multiple dictionaries will be produced. If the input's
|
|
436
|
-
|
|
436
|
+
|
|
437
437
|
{"user":"stedolan","titles":["JQ Primer", "More JQ"]}
|
|
438
|
-
|
|
438
|
+
|
|
439
439
|
then the expression
|
|
440
|
-
|
|
440
|
+
|
|
441
441
|
{user, title: .titles[]}
|
|
442
|
-
|
|
443
|
-
will produce two outputs:
|
|
444
|
-
|
|
442
|
+
|
|
443
|
+
will produce two outputs:
|
|
444
|
+
|
|
445
445
|
{"user":"stedolan", "title": "JQ Primer"}
|
|
446
446
|
{"user":"stedolan", "title": "More JQ"}
|
|
447
|
-
|
|
447
|
+
|
|
448
448
|
Putting parentheses around the key means it will be evaluated as an
|
|
449
449
|
expression. With the same input as above,
|
|
450
|
-
|
|
450
|
+
|
|
451
451
|
{(.user): .titles}
|
|
452
|
-
|
|
452
|
+
|
|
453
453
|
produces
|
|
454
|
-
|
|
454
|
+
|
|
455
455
|
{"stedolan": ["JQ Primer", "More JQ"]}
|
|
456
|
-
|
|
456
|
+
|
|
457
457
|
examples:
|
|
458
458
|
- program: '{user, title: .titles[]}'
|
|
459
459
|
input: '{"user":"stedolan","titles":["JQ Primer", "More JQ"]}'
|
|
@@ -472,7 +472,7 @@ sections:
|
|
|
472
472
|
etc.). However, jq never does implicit type conversions. If you
|
|
473
473
|
try to add a string to an object you'll get an error message and
|
|
474
474
|
no result.
|
|
475
|
-
|
|
475
|
+
|
|
476
476
|
entries:
|
|
477
477
|
- title: Addition - `+`
|
|
478
478
|
body: |
|
|
@@ -486,13 +486,13 @@ sections:
|
|
|
486
486
|
- **Arrays** are added by being concatenated into a larger array.
|
|
487
487
|
|
|
488
488
|
- **Strings** are added by being joined into a larger string.
|
|
489
|
-
|
|
489
|
+
|
|
490
490
|
- **Objects** are added by merging, that is, inserting all
|
|
491
491
|
the key-value pairs from both objects into a single
|
|
492
492
|
combined object. If both objects contain a value for the
|
|
493
493
|
same key, the object on the right of the `+` wins. (For
|
|
494
494
|
recursive merge use the `*` operator.)
|
|
495
|
-
|
|
495
|
+
|
|
496
496
|
`null` can be added to any value, and returns the other
|
|
497
497
|
value unchanged.
|
|
498
498
|
|
|
@@ -578,7 +578,7 @@ sections:
|
|
|
578
578
|
|
|
579
579
|
- title: "`keys`"
|
|
580
580
|
body: |
|
|
581
|
-
|
|
581
|
+
|
|
582
582
|
The builtin function `keys`, when given an object, returns
|
|
583
583
|
its keys in an array.
|
|
584
584
|
|
|
@@ -601,7 +601,7 @@ sections:
|
|
|
601
601
|
|
|
602
602
|
- title: "`has`"
|
|
603
603
|
body: |
|
|
604
|
-
|
|
604
|
+
|
|
605
605
|
The builtin function `has` returns whether the input object
|
|
606
606
|
has the given key, or the input array has an element at the
|
|
607
607
|
given index.
|
|
@@ -620,25 +620,25 @@ sections:
|
|
|
620
620
|
|
|
621
621
|
- title: "`del`"
|
|
622
622
|
body: |
|
|
623
|
-
|
|
623
|
+
|
|
624
624
|
The builtin function `del` removes a key and its corresponding
|
|
625
625
|
value from an object.
|
|
626
|
-
|
|
626
|
+
|
|
627
627
|
examples:
|
|
628
628
|
- program: 'del(.foo)'
|
|
629
|
-
input: '
|
|
629
|
+
input: '{"foo": 42, "bar": 9001, "baz": 42}'
|
|
630
630
|
output: ['{"bar": 9001, "baz": 42}']
|
|
631
631
|
- program: 'del(.[1, 2])'
|
|
632
|
-
input: '[
|
|
632
|
+
input: '["foo", "bar", "baz"]'
|
|
633
633
|
output: ['["foo"]']
|
|
634
634
|
|
|
635
635
|
- title: "`to_entries`, `from_entries`, `with_entries`"
|
|
636
636
|
body: |
|
|
637
|
-
|
|
637
|
+
|
|
638
638
|
These functions convert between an object and an array of
|
|
639
639
|
key-value pairs. If `to_entries` is passed an object, then
|
|
640
640
|
for each `k: v` entry in the input, the output array
|
|
641
|
-
includes `{"key": k, "value": v}`.
|
|
641
|
+
includes `{"key": k, "value": v}`.
|
|
642
642
|
|
|
643
643
|
`from_entries` does the opposite conversion, and
|
|
644
644
|
`with_entries(foo)` is a shorthand for `to_entries |
|
|
@@ -659,7 +659,7 @@ sections:
|
|
|
659
659
|
|
|
660
660
|
- title: "`select`"
|
|
661
661
|
body: |
|
|
662
|
-
|
|
662
|
+
|
|
663
663
|
The function `select(foo)` produces its input unchanged if
|
|
664
664
|
`foo` returns true for that input, and produces no output
|
|
665
665
|
otherwise.
|
|
@@ -675,7 +675,7 @@ sections:
|
|
|
675
675
|
|
|
676
676
|
- title: "`arrays`, `objects`, `iterables`, `booleans`, `numbers`, `strings`, `nulls`, `values`, `scalars`"
|
|
677
677
|
body: |
|
|
678
|
-
|
|
678
|
+
|
|
679
679
|
These built-ins select only inputs that are arrays, objects,
|
|
680
680
|
iterables (arrays or objects), booleans, numbers, strings,
|
|
681
681
|
null, non-null values, and non-iterables, respectively.
|
|
@@ -687,7 +687,7 @@ sections:
|
|
|
687
687
|
|
|
688
688
|
- title: "`empty`"
|
|
689
689
|
body: |
|
|
690
|
-
|
|
690
|
+
|
|
691
691
|
`empty` returns no results. None at all. Not even `null`.
|
|
692
692
|
|
|
693
693
|
It's useful on occasion. You'll know if you need it :)
|
|
@@ -721,7 +721,7 @@ sections:
|
|
|
721
721
|
Outputs the paths to all the elements in its input (except it
|
|
722
722
|
does not output the empty list, representing . itself).
|
|
723
723
|
|
|
724
|
-
`paths` is equivalent to
|
|
724
|
+
`paths` is equivalent to
|
|
725
725
|
|
|
726
726
|
def paths: path(recurse(if (type|. == "array" or . == "object") then .[] else empty end))|select(length > 0);
|
|
727
727
|
|
|
@@ -765,13 +765,13 @@ sections:
|
|
|
765
765
|
|
|
766
766
|
- title: "`any`"
|
|
767
767
|
body: |
|
|
768
|
-
|
|
768
|
+
|
|
769
769
|
The filter `any` takes as input an array of boolean values,
|
|
770
|
-
and produces `true` as output if any of the
|
|
771
|
-
the array
|
|
772
|
-
|
|
770
|
+
and produces `true` as output if any of the elements of
|
|
771
|
+
the array are `true`.
|
|
772
|
+
|
|
773
773
|
If the input is an empty array, `any` returns `false`.
|
|
774
|
-
|
|
774
|
+
|
|
775
775
|
examples:
|
|
776
776
|
- program: any
|
|
777
777
|
input: '[true, false]'
|
|
@@ -785,13 +785,13 @@ sections:
|
|
|
785
785
|
|
|
786
786
|
- title: "`all`"
|
|
787
787
|
body: |
|
|
788
|
-
|
|
788
|
+
|
|
789
789
|
The filter `all` takes as input an array of boolean values,
|
|
790
|
-
and produces `true` as output if all of the
|
|
790
|
+
and produces `true` as output if all of the elements of
|
|
791
791
|
the array are `true`.
|
|
792
|
-
|
|
792
|
+
|
|
793
793
|
If the input is an empty array, `all` returns `true`.
|
|
794
|
-
|
|
794
|
+
|
|
795
795
|
examples:
|
|
796
796
|
- program: all
|
|
797
797
|
input: '[true, false]'
|
|
@@ -805,10 +805,10 @@ sections:
|
|
|
805
805
|
|
|
806
806
|
- title: "`range`"
|
|
807
807
|
body: |
|
|
808
|
-
|
|
808
|
+
|
|
809
809
|
The `range` function produces a range of numbers. `range(4;10)`
|
|
810
810
|
produces 6 numbers, from 4 (inclusive) to 10 (exclusive). The numbers
|
|
811
|
-
are produced as separate outputs. Use `[range(4;10)]` to get a range as
|
|
811
|
+
are produced as separate outputs. Use `[range(4;10)]` to get a range as
|
|
812
812
|
an array.
|
|
813
813
|
|
|
814
814
|
examples:
|
|
@@ -818,7 +818,7 @@ sections:
|
|
|
818
818
|
- program: '[range(2;4)]'
|
|
819
819
|
input: 'null'
|
|
820
820
|
output: ['[2,3]']
|
|
821
|
-
|
|
821
|
+
|
|
822
822
|
- title: "`floor`"
|
|
823
823
|
body: |
|
|
824
824
|
|
|
@@ -828,7 +828,7 @@ sections:
|
|
|
828
828
|
- program: 'floor'
|
|
829
829
|
input: '3.14159'
|
|
830
830
|
output: ['3']
|
|
831
|
-
|
|
831
|
+
|
|
832
832
|
- title: "`sqrt`"
|
|
833
833
|
body: |
|
|
834
834
|
|
|
@@ -838,7 +838,7 @@ sections:
|
|
|
838
838
|
- program: 'sqrt'
|
|
839
839
|
input: '9'
|
|
840
840
|
output: ['3']
|
|
841
|
-
|
|
841
|
+
|
|
842
842
|
- title: "`tonumber`"
|
|
843
843
|
body: |
|
|
844
844
|
|
|
@@ -865,7 +865,7 @@ sections:
|
|
|
865
865
|
|
|
866
866
|
- title: "`type`"
|
|
867
867
|
body: |
|
|
868
|
-
|
|
868
|
+
|
|
869
869
|
The `type` function returns the type of its argument as a
|
|
870
870
|
string, which is one of null, boolean, number, string, array
|
|
871
871
|
or object.
|
|
@@ -877,7 +877,7 @@ sections:
|
|
|
877
877
|
|
|
878
878
|
- title: "`sort, sort_by`"
|
|
879
879
|
body: |
|
|
880
|
-
|
|
880
|
+
|
|
881
881
|
The `sort` functions sorts its input, which must be an
|
|
882
882
|
array. Values are sorted in the following order:
|
|
883
883
|
|
|
@@ -909,7 +909,7 @@ sections:
|
|
|
909
909
|
|
|
910
910
|
- title: "`group_by`"
|
|
911
911
|
body: |
|
|
912
|
-
|
|
912
|
+
|
|
913
913
|
`group_by(.foo)` takes as input an array, groups the
|
|
914
914
|
elements having the same `.foo` field into separate arrays,
|
|
915
915
|
and produces all of these arrays as elements of a larger
|
|
@@ -926,7 +926,7 @@ sections:
|
|
|
926
926
|
|
|
927
927
|
- title: "`min`, `max`, `min_by`, `max_by`"
|
|
928
928
|
body: |
|
|
929
|
-
|
|
929
|
+
|
|
930
930
|
Find the minimum or maximum element of the input array. The
|
|
931
931
|
`_by` versions allow you to specify a particular field or
|
|
932
932
|
property to examine, e.g. `min_by(.foo)` finds the object
|
|
@@ -942,7 +942,7 @@ sections:
|
|
|
942
942
|
|
|
943
943
|
- title: "`unique`"
|
|
944
944
|
body: |
|
|
945
|
-
|
|
945
|
+
|
|
946
946
|
The `unique` function takes as input an array and produces
|
|
947
947
|
an array of the same elements, in sorted order, with
|
|
948
948
|
duplicates removed.
|
|
@@ -954,25 +954,25 @@ sections:
|
|
|
954
954
|
|
|
955
955
|
- title: "`unique_by`"
|
|
956
956
|
body: |
|
|
957
|
-
|
|
957
|
+
|
|
958
958
|
The `unique_by(.foo)` function takes as input an array and produces
|
|
959
959
|
an array of the same elements, in sorted order, with
|
|
960
960
|
elqements with a duplicate `.foo` field removed. Think of it as making
|
|
961
961
|
an array by taking one element out of every group produced by
|
|
962
962
|
`group_by`.
|
|
963
|
-
|
|
963
|
+
|
|
964
964
|
examples:
|
|
965
965
|
- program: 'unique_by(.foo)'
|
|
966
966
|
input: '[{"foo": 1, "bar": 2}, {"foo": 1, "bar": 3}, {"foo": 4, "bar": 5}]'
|
|
967
967
|
output: ['[{"foo": 1, "bar": 2}, {"foo": 4, "bar": 5}]']
|
|
968
968
|
- program: 'unique_by(length)'
|
|
969
969
|
input: '["chunky", "bacon", "kitten", "cicada", "asparagus"]'
|
|
970
|
-
output: ['["
|
|
970
|
+
output: ['["bacon", "chunky", "asparagus"]']
|
|
971
971
|
|
|
972
972
|
|
|
973
973
|
- title: "`reverse`"
|
|
974
974
|
body: |
|
|
975
|
-
|
|
975
|
+
|
|
976
976
|
This function reverses an array.
|
|
977
977
|
|
|
978
978
|
examples:
|
|
@@ -1038,7 +1038,7 @@ sections:
|
|
|
1038
1038
|
- program: 'index(", ")'
|
|
1039
1039
|
input: '"a,b, cd, efg, hijk"'
|
|
1040
1040
|
output: ['3']
|
|
1041
|
-
- program: 'rindex(", ")
|
|
1041
|
+
- program: 'rindex(", ")'
|
|
1042
1042
|
input: '"a,b, cd, efg, hijk"'
|
|
1043
1043
|
output: ['12']
|
|
1044
1044
|
|
|
@@ -1060,7 +1060,7 @@ sections:
|
|
|
1060
1060
|
examples:
|
|
1061
1061
|
- program: '[.[]|endswith("foo")]'
|
|
1062
1062
|
input: '["foobar", "barfoo"]'
|
|
1063
|
-
output: ['[false, true
|
|
1063
|
+
output: ['[false, true]']
|
|
1064
1064
|
|
|
1065
1065
|
- title: "`ltrimstr`"
|
|
1066
1066
|
body: |
|
|
@@ -1117,12 +1117,12 @@ sections:
|
|
|
1117
1117
|
|
|
1118
1118
|
- title: "`join`"
|
|
1119
1119
|
body: |
|
|
1120
|
-
|
|
1120
|
+
|
|
1121
1121
|
Joins the array of elements given as input, using the
|
|
1122
1122
|
argument as separator. It is the inverse of `split`: that is,
|
|
1123
1123
|
running `split("foo") | join("foo")` over any input string
|
|
1124
1124
|
returns said input string.
|
|
1125
|
-
|
|
1125
|
+
|
|
1126
1126
|
examples:
|
|
1127
1127
|
- program: 'join(", ")'
|
|
1128
1128
|
input: '["a","b,c,d","e"]'
|
|
@@ -1131,7 +1131,7 @@ sections:
|
|
|
1131
1131
|
|
|
1132
1132
|
- title: "`recurse`"
|
|
1133
1133
|
body: |
|
|
1134
|
-
|
|
1134
|
+
|
|
1135
1135
|
The `recurse` function allows you to search through a
|
|
1136
1136
|
recursive structure, and extract interesting data from all
|
|
1137
1137
|
levels. Suppose your input represents a filesystem:
|
|
@@ -1143,7 +1143,7 @@ sections:
|
|
|
1143
1143
|
{"name": "/home", "children": [
|
|
1144
1144
|
{"name": "/home/stephen", "children": [
|
|
1145
1145
|
{"name": "/home/stephen/jq", "children": []}]}]}]}
|
|
1146
|
-
|
|
1146
|
+
|
|
1147
1147
|
Now suppose you want to extract all of the filenames
|
|
1148
1148
|
present. You need to retrieve `.name`, `.children[].name`,
|
|
1149
1149
|
`.children[].children[].name`, and so on. You can do this
|
|
@@ -1154,7 +1154,7 @@ sections:
|
|
|
1154
1154
|
examples:
|
|
1155
1155
|
- program: 'recurse(.foo[])'
|
|
1156
1156
|
input: '{"foo":[{"foo": []}, {"foo":[{"foo":[]}]}]}'
|
|
1157
|
-
output:
|
|
1157
|
+
output:
|
|
1158
1158
|
- '{"foo":[{"foo":[]},{"foo":[{"foo":[]}]}]}'
|
|
1159
1159
|
- '{"foo":[]}'
|
|
1160
1160
|
- '{"foo":[{"foo":[]}]}'
|
|
@@ -1162,14 +1162,14 @@ sections:
|
|
|
1162
1162
|
|
|
1163
1163
|
- title: "`recurse_down`"
|
|
1164
1164
|
body: |
|
|
1165
|
-
|
|
1165
|
+
|
|
1166
1166
|
A quieter version of `recurse(.[])`, equivalent to:
|
|
1167
1167
|
|
|
1168
1168
|
def recurse_down: recurse(.[]?);
|
|
1169
1169
|
|
|
1170
1170
|
- title: "`..`"
|
|
1171
1171
|
body: |
|
|
1172
|
-
|
|
1172
|
+
|
|
1173
1173
|
Short-hand for `recurse_down`. This is intended to resemble
|
|
1174
1174
|
the XPath `//` operator. Note that `..a` does not work; use
|
|
1175
1175
|
`..|a` instead.
|
|
@@ -1190,7 +1190,7 @@ sections:
|
|
|
1190
1190
|
- program: '"The input was \(.), which is one less than \(.+1)"'
|
|
1191
1191
|
input: '42'
|
|
1192
1192
|
output: ['"The input was 42, which is one less than 43"']
|
|
1193
|
-
|
|
1193
|
+
|
|
1194
1194
|
- title: "Convert to/from JSON"
|
|
1195
1195
|
body: |
|
|
1196
1196
|
|
|
@@ -1238,17 +1238,17 @@ sections:
|
|
|
1238
1238
|
characters to a `%xx` sequence.
|
|
1239
1239
|
|
|
1240
1240
|
* `@csv`:
|
|
1241
|
-
|
|
1241
|
+
|
|
1242
1242
|
The input must be an array, and it is rendered as CSV
|
|
1243
1243
|
with double quotes for strings, and quotes escaped by
|
|
1244
1244
|
repetition.
|
|
1245
1245
|
|
|
1246
1246
|
* `@sh`:
|
|
1247
|
-
|
|
1247
|
+
|
|
1248
1248
|
The input is escaped suitable for use in a command-line
|
|
1249
1249
|
for a POSIX shell. If the input is an array, the output
|
|
1250
1250
|
will be a series of space-separated strings.
|
|
1251
|
-
|
|
1251
|
+
|
|
1252
1252
|
* `@base64`:
|
|
1253
1253
|
|
|
1254
1254
|
The input is converted to base64 as specified by RFC 4648.
|
|
@@ -1281,7 +1281,7 @@ sections:
|
|
|
1281
1281
|
- program: '@sh "echo \(.)"'
|
|
1282
1282
|
input: "\"O'Hara's Ale\""
|
|
1283
1283
|
output: ["\"echo 'O'\\\\''Hara'\\\\''s Ale'\""]
|
|
1284
|
-
|
|
1284
|
+
|
|
1285
1285
|
- title: Conditionals and Comparisons
|
|
1286
1286
|
entries:
|
|
1287
1287
|
- title: "`==`, `!=`"
|
|
@@ -1293,7 +1293,7 @@ sections:
|
|
|
1293
1293
|
to numbers. If you're coming from Javascript, jq's == is like
|
|
1294
1294
|
Javascript's === - considering values equal only when they have the
|
|
1295
1295
|
same type as well as the same value.
|
|
1296
|
-
|
|
1296
|
+
|
|
1297
1297
|
!= is "not equal", and 'a != b' returns the opposite value of 'a == b'
|
|
1298
1298
|
|
|
1299
1299
|
examples:
|
|
@@ -1306,7 +1306,7 @@ sections:
|
|
|
1306
1306
|
`if A then B else C end` will act the same as `B` if `A`
|
|
1307
1307
|
produces a value other than false or null, but act the same
|
|
1308
1308
|
as `C` otherwise.
|
|
1309
|
-
|
|
1309
|
+
|
|
1310
1310
|
Checking for false or null is a simpler notion of
|
|
1311
1311
|
"truthiness" than is found in Javascript or Python, but it
|
|
1312
1312
|
means that you'll sometimes have to be more explicit about
|
|
@@ -1314,11 +1314,11 @@ sections:
|
|
|
1314
1314
|
string is empty using `if .name then A else B end`, you'll
|
|
1315
1315
|
need something more like `if (.name | length) > 0 then A else
|
|
1316
1316
|
B end` instead.
|
|
1317
|
-
|
|
1318
|
-
If the condition A produces multiple results,
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1317
|
+
|
|
1318
|
+
If the condition `A` produces multiple results, then `B` is evaluated
|
|
1319
|
+
once for each result that is not false or null, and `C` is evaluated
|
|
1320
|
+
once for each false or null.
|
|
1321
|
+
|
|
1322
1322
|
More cases can be added to an if using `elif A then B` syntax.
|
|
1323
1323
|
|
|
1324
1324
|
examples:
|
|
@@ -1332,10 +1332,10 @@ sections:
|
|
|
1332
1332
|
end
|
|
1333
1333
|
input: 2
|
|
1334
1334
|
output: ['"many"']
|
|
1335
|
-
|
|
1335
|
+
|
|
1336
1336
|
- title: "`>, >=, <=, <`"
|
|
1337
1337
|
body: |
|
|
1338
|
-
|
|
1338
|
+
|
|
1339
1339
|
The comparison operators `>`, `>=`, `<=`, `<` return whether
|
|
1340
1340
|
their left argument is greater than, greater than or equal
|
|
1341
1341
|
to, less than or equal to or less than their right argument
|
|
@@ -1362,14 +1362,14 @@ sections:
|
|
|
1362
1362
|
so it is called as a filter to which things can be piped
|
|
1363
1363
|
rather than with special syntax, as in `.foo and .bar |
|
|
1364
1364
|
not`.
|
|
1365
|
-
|
|
1365
|
+
|
|
1366
1366
|
These three only produce the values "true" and "false", and
|
|
1367
1367
|
so are only useful for genuine Boolean operations, rather
|
|
1368
1368
|
than the common Perl/Python/Ruby idiom of
|
|
1369
1369
|
"value_that_may_be_null or default". If you want to use this
|
|
1370
1370
|
form of "or", picking between two values rather than
|
|
1371
1371
|
evaluating a condition, see the "//" operator below.
|
|
1372
|
-
|
|
1372
|
+
|
|
1373
1373
|
examples:
|
|
1374
1374
|
- program: '42 and "a string"'
|
|
1375
1375
|
input: 'null'
|
|
@@ -1407,7 +1407,7 @@ sections:
|
|
|
1407
1407
|
- program: '.foo // 42'
|
|
1408
1408
|
input: '{}'
|
|
1409
1409
|
output: [42]
|
|
1410
|
-
|
|
1410
|
+
|
|
1411
1411
|
- title: Advanced features
|
|
1412
1412
|
body: |
|
|
1413
1413
|
Variables are an absolute necessity in most programming languages, but
|
|
@@ -1432,67 +1432,67 @@ sections:
|
|
|
1432
1432
|
entries:
|
|
1433
1433
|
- title: Variables
|
|
1434
1434
|
body: |
|
|
1435
|
-
|
|
1435
|
+
|
|
1436
1436
|
In jq, all filters have an input and an output, so manual
|
|
1437
1437
|
plumbing is not necessary to pass a value from one part of a program
|
|
1438
1438
|
to the next. Many expressions, for instance `a + b`, pass their input
|
|
1439
1439
|
to two distinct subexpressions (here `a` and `b` are both passed the
|
|
1440
1440
|
same input), so variables aren't usually necessary in order to use a
|
|
1441
1441
|
value twice.
|
|
1442
|
-
|
|
1442
|
+
|
|
1443
1443
|
For instance, calculating the average value of an array of numbers
|
|
1444
1444
|
requires a few variables in most languages - at least one to hold the
|
|
1445
1445
|
array, perhaps one for each element or for a loop counter. In jq, it's
|
|
1446
1446
|
simply `add / length` - the `add` expression is given the array and
|
|
1447
1447
|
produces its sum, and the `length` expression is given the array and
|
|
1448
1448
|
produces its length.
|
|
1449
|
-
|
|
1449
|
+
|
|
1450
1450
|
So, there's generally a cleaner way to solve most problems in jq than
|
|
1451
1451
|
defining variables. Still, sometimes they do make things easier, so jq
|
|
1452
1452
|
lets you define variables using `expression as $variable`. All
|
|
1453
1453
|
variable names start with `$`. Here's a slightly uglier version of the
|
|
1454
1454
|
array-averaging example:
|
|
1455
|
-
|
|
1455
|
+
|
|
1456
1456
|
length as $array_length | add / $array_length
|
|
1457
|
-
|
|
1457
|
+
|
|
1458
1458
|
We'll need a more complicated problem to find a situation where using
|
|
1459
1459
|
variables actually makes our lives easier.
|
|
1460
|
-
|
|
1461
|
-
|
|
1460
|
+
|
|
1461
|
+
|
|
1462
1462
|
Suppose we have an array of blog posts, with "author" and "title"
|
|
1463
1463
|
fields, and another object which is used to map author usernames to
|
|
1464
1464
|
real names. Our input looks like:
|
|
1465
|
-
|
|
1465
|
+
|
|
1466
1466
|
{"posts": [{"title": "Frist psot", "author": "anon"},
|
|
1467
1467
|
{"title": "A well-written article", "author": "person1"}],
|
|
1468
1468
|
"realnames": {"anon": "Anonymous Coward",
|
|
1469
1469
|
"person1": "Person McPherson"}}
|
|
1470
|
-
|
|
1470
|
+
|
|
1471
1471
|
We want to produce the posts with the author field containing a real
|
|
1472
1472
|
name, as in:
|
|
1473
|
-
|
|
1473
|
+
|
|
1474
1474
|
{"title": "Frist psot", "author": "Anonymous Coward"}
|
|
1475
1475
|
{"title": "A well-written article", "author": "Person McPherson"}
|
|
1476
|
-
|
|
1476
|
+
|
|
1477
1477
|
We use a variable, $names, to store the realnames object, so that we
|
|
1478
1478
|
can refer to it later when looking up author usernames:
|
|
1479
|
-
|
|
1479
|
+
|
|
1480
1480
|
.realnames as $names | .posts[] | {title, author: $names[.author]}
|
|
1481
|
-
|
|
1481
|
+
|
|
1482
1482
|
The expression `exp as $x | ...` means: for each value of expression
|
|
1483
1483
|
`exp`, run the rest of the pipeline with the entire original input, and
|
|
1484
|
-
with `$x` set to that value. Thus `as` functions as something of a
|
|
1484
|
+
with `$x` set to that value. Thus `as` functions as something of a
|
|
1485
1485
|
foreach loop.
|
|
1486
1486
|
|
|
1487
1487
|
Variables are scoped over the rest of the expression that defines
|
|
1488
|
-
them, so
|
|
1489
|
-
|
|
1488
|
+
them, so
|
|
1489
|
+
|
|
1490
1490
|
.realnames as $names | (.posts[] | {title, author: $names[.author]})
|
|
1491
|
-
|
|
1492
|
-
will work, but
|
|
1493
|
-
|
|
1491
|
+
|
|
1492
|
+
will work, but
|
|
1493
|
+
|
|
1494
1494
|
(.realnames as $names | .posts[]) | {title, author: $names[.author]}
|
|
1495
|
-
|
|
1495
|
+
|
|
1496
1496
|
won't.
|
|
1497
1497
|
|
|
1498
1498
|
examples:
|
|
@@ -1502,11 +1502,11 @@ sections:
|
|
|
1502
1502
|
|
|
1503
1503
|
- title: 'Defining Functions'
|
|
1504
1504
|
body: |
|
|
1505
|
-
|
|
1505
|
+
|
|
1506
1506
|
You can give a filter a name using "def" syntax:
|
|
1507
1507
|
|
|
1508
1508
|
def increment: . + 1;
|
|
1509
|
-
|
|
1509
|
+
|
|
1510
1510
|
From then on, `increment` is usable as a filter just like a
|
|
1511
1511
|
builtin function (in fact, this is how some of the builtins
|
|
1512
1512
|
are defined). A function may take arguments:
|
|
@@ -1537,19 +1537,19 @@ sections:
|
|
|
1537
1537
|
|
|
1538
1538
|
- title: Reduce
|
|
1539
1539
|
body: |
|
|
1540
|
-
|
|
1540
|
+
|
|
1541
1541
|
The `reduce` syntax in jq allows you to combine all of the
|
|
1542
1542
|
results of an expression by accumulating them into a single
|
|
1543
1543
|
answer. As an example, we'll pass `[3,2,1]` to this expression:
|
|
1544
1544
|
|
|
1545
1545
|
reduce .[] as $item (0; . + $item)
|
|
1546
|
-
|
|
1546
|
+
|
|
1547
1547
|
For each result that `.[]` produces, `. + $item` is run to
|
|
1548
1548
|
accumulate a running total, starting from 0. In this
|
|
1549
1549
|
example, `.[]` produces the results 3, 2, and 1, so the
|
|
1550
1550
|
effect is similar to running something like this:
|
|
1551
1551
|
|
|
1552
|
-
0 | (3 as $item | . + $item) |
|
|
1552
|
+
0 | (3 as $item | . + $item) |
|
|
1553
1553
|
(2 as $item | . + $item) |
|
|
1554
1554
|
(1 as $item | . + $item)
|
|
1555
1555
|
|
|
@@ -1557,7 +1557,7 @@ sections:
|
|
|
1557
1557
|
- program: 'reduce .[] as $item (0; . + $item)'
|
|
1558
1558
|
input: '[10,2,5,3]'
|
|
1559
1559
|
output: ['20']
|
|
1560
|
-
|
|
1560
|
+
|
|
1561
1561
|
|
|
1562
1562
|
- title: Assignment
|
|
1563
1563
|
body: |
|
|
@@ -1579,14 +1579,14 @@ sections:
|
|
|
1579
1579
|
entries:
|
|
1580
1580
|
- title: "`=`"
|
|
1581
1581
|
body: |
|
|
1582
|
-
|
|
1582
|
+
|
|
1583
1583
|
The filter `.foo = 1` will take as input an object
|
|
1584
1584
|
and produce as output an object with the "foo" field set to
|
|
1585
1585
|
1. There is no notion of "modifying" or "changing" something
|
|
1586
1586
|
in jq - all jq values are immutable. For instance,
|
|
1587
|
-
|
|
1587
|
+
|
|
1588
1588
|
.foo = .bar | .foo.baz = 1
|
|
1589
|
-
|
|
1589
|
+
|
|
1590
1590
|
will not have the side-effect of setting .bar.baz to be set
|
|
1591
1591
|
to 1, as the similar-looking program in Javascript, Python,
|
|
1592
1592
|
Ruby or other languages would. Unlike these languages (but
|
|
@@ -1595,7 +1595,7 @@ sections:
|
|
|
1595
1595
|
"the same object". They can be equal, or not equal, but if
|
|
1596
1596
|
we change one of them in no circumstances will the other
|
|
1597
1597
|
change behind our backs.
|
|
1598
|
-
|
|
1598
|
+
|
|
1599
1599
|
This means that it's impossible to build circular values in
|
|
1600
1600
|
jq (such as an array whose first element is itself). This is
|
|
1601
1601
|
quite intentional, and ensures that anything a jq program
|
|
@@ -1608,14 +1608,14 @@ sections:
|
|
|
1608
1608
|
works out the new value for the property being assigned to by running
|
|
1609
1609
|
the old value through this expression. For instance, .foo |= .+1 will
|
|
1610
1610
|
build an object with the "foo" field set to the input's "foo" plus 1.
|
|
1611
|
-
|
|
1611
|
+
|
|
1612
1612
|
This example should show the difference between '=' and '|=':
|
|
1613
|
-
|
|
1613
|
+
|
|
1614
1614
|
Provide input '{"a": {"b": 10}, "b": 20}' to the programs:
|
|
1615
|
-
|
|
1615
|
+
|
|
1616
1616
|
.a = .b
|
|
1617
1617
|
.a |= .b
|
|
1618
|
-
|
|
1618
|
+
|
|
1619
1619
|
The former will set the "a" field of the input to the "b" field of the
|
|
1620
1620
|
input, and produce the output {"a": 20}. The latter will set the "a"
|
|
1621
1621
|
field of the input to the "a" field's "b" field, producing {"a": 10}.
|
|
@@ -1630,43 +1630,43 @@ sections:
|
|
|
1630
1630
|
- program: .foo += 1
|
|
1631
1631
|
input: '{"foo": 42}'
|
|
1632
1632
|
output: ['{"foo": 43}']
|
|
1633
|
-
|
|
1633
|
+
|
|
1634
1634
|
- title: Complex assignments
|
|
1635
1635
|
body: |
|
|
1636
1636
|
Lots more things are allowed on the left-hand side of a jq assignment
|
|
1637
1637
|
than in most langauges. We've already seen simple field accesses on
|
|
1638
1638
|
the left hand side, and it's no surprise that array accesses work just
|
|
1639
1639
|
as well:
|
|
1640
|
-
|
|
1640
|
+
|
|
1641
1641
|
.posts[0].title = "JQ Manual"
|
|
1642
|
-
|
|
1642
|
+
|
|
1643
1643
|
What may come as a surprise is that the expression on the left may
|
|
1644
1644
|
produce multiple results, referring to different points in the input
|
|
1645
1645
|
document:
|
|
1646
|
-
|
|
1646
|
+
|
|
1647
1647
|
.posts[].comments |= . + ["this is great"]
|
|
1648
|
-
|
|
1648
|
+
|
|
1649
1649
|
That example appends the string "this is great" to the "comments"
|
|
1650
1650
|
array of each post in the input (where the input is an object with a
|
|
1651
1651
|
field "posts" which is an array of posts).
|
|
1652
|
-
|
|
1652
|
+
|
|
1653
1653
|
When jq encounters an assignment like 'a = b', it records the "path"
|
|
1654
1654
|
taken to select a part of the input document while executing a. This
|
|
1655
1655
|
path is then used to find which part of the input to change while
|
|
1656
1656
|
executing the assignment. Any filter may be used on the
|
|
1657
1657
|
left-hand side of an equals - whichever paths it selects from the
|
|
1658
1658
|
input will be where the assignment is performed.
|
|
1659
|
-
|
|
1659
|
+
|
|
1660
1660
|
This is a very powerful operation. Suppose we wanted to add a comment
|
|
1661
1661
|
to blog posts, using the same "blog" input above. This time, we only
|
|
1662
1662
|
want to comment on the posts written by "stedolan". We can find those
|
|
1663
1663
|
posts using the "select" function described earlier:
|
|
1664
|
-
|
|
1664
|
+
|
|
1665
1665
|
.posts[] | select(.author == "stedolan")
|
|
1666
|
-
|
|
1666
|
+
|
|
1667
1667
|
The paths provided by this operation point to each of the posts that
|
|
1668
1668
|
"stedolan" wrote, and we can comment on each of them in the same way
|
|
1669
1669
|
that we did before:
|
|
1670
|
-
|
|
1670
|
+
|
|
1671
1671
|
(.posts[] | select(.author == "stedolan") | .comments) |=
|
|
1672
1672
|
. + ["terrible."]
|