@port-labs/jq-node-bindings 0.0.4 → 0.0.5

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.
Files changed (286) hide show
  1. package/binding.gyp +3 -3
  2. package/configure +8 -6
  3. package/deps/jq/.travis.yml +184 -35
  4. package/deps/jq/AUTHORS +31 -30
  5. package/deps/jq/COPYING +2 -2
  6. package/deps/jq/KEYS +8 -0
  7. package/deps/jq/Makefile.am +85 -70
  8. package/deps/jq/NEWS +5 -4
  9. package/deps/jq/README.md +18 -9
  10. package/deps/jq/appveyor.yml +53 -0
  11. package/deps/jq/compile-ios.sh +5 -5
  12. package/deps/jq/config/m4/check-math-func.m4 +7 -2
  13. package/deps/jq/configure.ac +130 -68
  14. package/deps/jq/docs/Rakefile +14 -135
  15. package/deps/jq/docs/Rakefile.manual +49 -0
  16. package/deps/jq/docs/Rakefile.website +76 -0
  17. package/deps/jq/docs/content/2.download/default.yml +115 -39
  18. package/deps/jq/docs/content/3.manual/manual.yml +641 -231
  19. package/deps/jq/docs/content/3.manual/v1.3/manual.yml +130 -130
  20. package/deps/jq/docs/content/3.manual/v1.4/manual.yml +160 -160
  21. package/deps/jq/docs/content/3.manual/v1.5/manual.yml +2878 -0
  22. package/deps/jq/docs/content/3.manual/v1.6/manual.yml +3287 -0
  23. package/deps/jq/docs/content/index/index.yml +28 -6
  24. package/deps/jq/docs/public/.htaccess +2 -2
  25. package/deps/jq/docs/public/css/base.scss +141 -59
  26. package/deps/jq/docs/public/js/manual-search.js +52 -0
  27. package/deps/jq/docs/site.yml +1 -10
  28. package/deps/jq/docs/templates/default.liquid +10 -10
  29. package/deps/jq/docs/templates/index.liquid +45 -32
  30. package/deps/jq/docs/templates/manual.liquid +67 -90
  31. package/deps/jq/docs/templates/shared/_footer.liquid +10 -5
  32. package/deps/jq/docs/templates/shared/_head.liquid +17 -12
  33. package/deps/jq/docs/templates/shared/_navbar.liquid +27 -0
  34. package/deps/jq/jq.1.prebuilt +523 -139
  35. package/deps/jq/modules/oniguruma/AUTHORS +1 -0
  36. package/deps/jq/modules/oniguruma/CMakeLists.txt +86 -0
  37. package/deps/jq/modules/oniguruma/COPYING +28 -0
  38. package/deps/jq/modules/oniguruma/ChangeLog +0 -0
  39. package/deps/jq/modules/oniguruma/HISTORY +2138 -0
  40. package/deps/jq/modules/oniguruma/Makefile.am +33 -0
  41. package/deps/jq/modules/oniguruma/NEWS +0 -0
  42. package/deps/jq/modules/oniguruma/README +189 -0
  43. package/deps/jq/modules/oniguruma/README.ja +195 -0
  44. package/deps/jq/modules/oniguruma/README.md +203 -0
  45. package/deps/jq/modules/oniguruma/cmake/dist.cmake +321 -0
  46. package/deps/jq/modules/oniguruma/compile +348 -0
  47. package/deps/jq/modules/oniguruma/config.guess +1754 -0
  48. package/deps/jq/modules/oniguruma/config.sub +1890 -0
  49. package/deps/jq/modules/oniguruma/configure.ac +87 -0
  50. package/deps/jq/modules/oniguruma/contributed/libfuzzer-onig.cpp +31 -0
  51. package/deps/jq/modules/oniguruma/depcomp +791 -0
  52. package/deps/jq/modules/oniguruma/dist.info +10 -0
  53. package/deps/jq/modules/oniguruma/doc/API +660 -0
  54. package/deps/jq/modules/oniguruma/doc/API.ja +667 -0
  55. package/deps/jq/modules/oniguruma/doc/FAQ +12 -0
  56. package/deps/jq/modules/oniguruma/doc/FAQ.ja +22 -0
  57. package/deps/jq/modules/oniguruma/doc/RE +436 -0
  58. package/deps/jq/modules/oniguruma/doc/RE.ja +448 -0
  59. package/deps/jq/modules/oniguruma/doc/UNICODE_PROPERTIES +698 -0
  60. package/deps/jq/modules/oniguruma/index.html +181 -0
  61. package/deps/jq/modules/oniguruma/index_ja.html +184 -0
  62. package/deps/jq/modules/oniguruma/install-sh +541 -0
  63. package/deps/jq/modules/oniguruma/m4/.whatever +0 -0
  64. package/deps/jq/modules/oniguruma/make_win32.bat +3 -0
  65. package/deps/jq/modules/oniguruma/make_win64.bat +3 -0
  66. package/deps/jq/modules/oniguruma/missing +215 -0
  67. package/deps/jq/modules/oniguruma/onig-config.in +78 -0
  68. package/deps/jq/modules/oniguruma/oniguruma.pc.cmake.in +13 -0
  69. package/deps/jq/modules/oniguruma/oniguruma.pc.in +14 -0
  70. package/deps/jq/modules/oniguruma/sample/CMakeLists.txt +28 -0
  71. package/deps/jq/modules/oniguruma/sample/Makefile.am +34 -0
  72. package/deps/jq/modules/oniguruma/sample/bug_fix.c +131 -0
  73. package/deps/jq/modules/oniguruma/sample/crnl.c +127 -0
  74. package/deps/jq/modules/oniguruma/sample/encode.c +308 -0
  75. package/deps/jq/modules/oniguruma/sample/listcap.c +110 -0
  76. package/deps/jq/modules/oniguruma/sample/names.c +75 -0
  77. package/deps/jq/modules/oniguruma/sample/posix.c +96 -0
  78. package/deps/jq/modules/oniguruma/sample/scan.c +88 -0
  79. package/deps/jq/modules/oniguruma/sample/simple.c +59 -0
  80. package/deps/jq/modules/oniguruma/sample/sql.c +76 -0
  81. package/deps/jq/modules/oniguruma/sample/syntax.c +76 -0
  82. package/deps/jq/modules/oniguruma/sample/user_property.c +87 -0
  83. package/deps/jq/modules/oniguruma/src/Makefile.am +58 -0
  84. package/deps/jq/modules/oniguruma/src/Makefile.windows +183 -0
  85. package/deps/jq/modules/oniguruma/src/ascii.c +61 -0
  86. package/deps/jq/modules/oniguruma/src/big5.c +190 -0
  87. package/deps/jq/modules/oniguruma/src/config.h.cmake.in +71 -0
  88. package/deps/jq/modules/oniguruma/src/config.h.win32 +84 -0
  89. package/deps/jq/modules/oniguruma/src/config.h.win64 +84 -0
  90. package/deps/jq/modules/oniguruma/src/cp1251.c +203 -0
  91. package/deps/jq/modules/oniguruma/src/euc_jp.c +310 -0
  92. package/deps/jq/modules/oniguruma/src/euc_jp_prop.c +158 -0
  93. package/deps/jq/modules/oniguruma/src/euc_jp_prop.gperf +27 -0
  94. package/deps/jq/modules/oniguruma/src/euc_kr.c +188 -0
  95. package/deps/jq/modules/oniguruma/src/euc_tw.c +171 -0
  96. package/deps/jq/modules/oniguruma/src/gb18030.c +538 -0
  97. package/deps/jq/modules/oniguruma/src/gperf_fold_key_conv.py +67 -0
  98. package/deps/jq/modules/oniguruma/src/gperf_unfold_key_conv.py +55 -0
  99. package/deps/jq/modules/oniguruma/src/iso8859_1.c +275 -0
  100. package/deps/jq/modules/oniguruma/src/iso8859_10.c +242 -0
  101. package/deps/jq/modules/oniguruma/src/iso8859_11.c +99 -0
  102. package/deps/jq/modules/oniguruma/src/iso8859_13.c +231 -0
  103. package/deps/jq/modules/oniguruma/src/iso8859_14.c +244 -0
  104. package/deps/jq/modules/oniguruma/src/iso8859_15.c +238 -0
  105. package/deps/jq/modules/oniguruma/src/iso8859_16.c +240 -0
  106. package/deps/jq/modules/oniguruma/src/iso8859_2.c +238 -0
  107. package/deps/jq/modules/oniguruma/src/iso8859_3.c +238 -0
  108. package/deps/jq/modules/oniguruma/src/iso8859_4.c +240 -0
  109. package/deps/jq/modules/oniguruma/src/iso8859_5.c +229 -0
  110. package/deps/jq/modules/oniguruma/src/iso8859_6.c +99 -0
  111. package/deps/jq/modules/oniguruma/src/iso8859_7.c +225 -0
  112. package/deps/jq/modules/oniguruma/src/iso8859_8.c +99 -0
  113. package/deps/jq/modules/oniguruma/src/iso8859_9.c +231 -0
  114. package/deps/jq/modules/oniguruma/src/koi8.c +253 -0
  115. package/deps/jq/modules/oniguruma/src/koi8_r.c +215 -0
  116. package/deps/jq/modules/oniguruma/src/make_unicode_fold.sh +22 -0
  117. package/deps/jq/modules/oniguruma/src/make_unicode_fold_data.py +306 -0
  118. package/deps/jq/modules/oniguruma/src/make_unicode_property.sh +18 -0
  119. package/deps/jq/modules/oniguruma/src/make_unicode_property_data.py +545 -0
  120. package/deps/jq/modules/oniguruma/src/mktable.c +1184 -0
  121. package/deps/jq/modules/oniguruma/src/onig_init.c +45 -0
  122. package/deps/jq/modules/oniguruma/src/oniggnu.h +85 -0
  123. package/deps/jq/modules/oniguruma/src/onigposix.h +169 -0
  124. package/deps/jq/modules/oniguruma/src/oniguruma.h +841 -0
  125. package/deps/jq/modules/oniguruma/src/regcomp.c +6300 -0
  126. package/deps/jq/modules/oniguruma/src/regenc.c +917 -0
  127. package/deps/jq/modules/oniguruma/src/regenc.h +243 -0
  128. package/deps/jq/modules/oniguruma/src/regerror.c +393 -0
  129. package/deps/jq/modules/oniguruma/src/regexec.c +3856 -0
  130. package/deps/jq/modules/oniguruma/src/regext.c +202 -0
  131. package/deps/jq/modules/oniguruma/src/reggnu.c +147 -0
  132. package/deps/jq/modules/oniguruma/src/regint.h +779 -0
  133. package/deps/jq/modules/oniguruma/src/regparse.c +5403 -0
  134. package/deps/jq/modules/oniguruma/src/regparse.h +351 -0
  135. package/deps/jq/modules/oniguruma/src/regposerr.c +105 -0
  136. package/deps/jq/modules/oniguruma/src/regposix.c +306 -0
  137. package/deps/jq/modules/oniguruma/src/regsyntax.c +315 -0
  138. package/deps/jq/modules/oniguruma/src/regtrav.c +76 -0
  139. package/deps/jq/modules/oniguruma/src/regversion.c +57 -0
  140. package/deps/jq/modules/oniguruma/src/sjis.c +341 -0
  141. package/deps/jq/modules/oniguruma/src/sjis_prop.c +158 -0
  142. package/deps/jq/modules/oniguruma/src/sjis_prop.gperf +27 -0
  143. package/deps/jq/modules/oniguruma/src/st.c +589 -0
  144. package/deps/jq/modules/oniguruma/src/st.h +68 -0
  145. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold1_key.c +2250 -0
  146. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold2_key.c +203 -0
  147. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold3_key.c +113 -0
  148. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold_data.c +1225 -0
  149. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_property_data.c +24742 -0
  150. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_property_data_posix.c +4846 -0
  151. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_unfold_key.c +2571 -0
  152. package/deps/jq/modules/oniguruma/src/unicode.c +664 -0
  153. package/deps/jq/modules/oniguruma/src/unicode_fold1_key.c +2548 -0
  154. package/deps/jq/modules/oniguruma/src/unicode_fold2_key.c +203 -0
  155. package/deps/jq/modules/oniguruma/src/unicode_fold3_key.c +113 -0
  156. package/deps/jq/modules/oniguruma/src/unicode_fold_data.c +1366 -0
  157. package/deps/jq/modules/oniguruma/src/unicode_property_data.c +25306 -0
  158. package/deps/jq/modules/oniguruma/src/unicode_property_data_posix.c +4940 -0
  159. package/deps/jq/modules/oniguruma/src/unicode_unfold_key.c +2854 -0
  160. package/deps/jq/modules/oniguruma/src/utf16_be.c +235 -0
  161. package/deps/jq/modules/oniguruma/src/utf16_le.c +245 -0
  162. package/deps/jq/modules/oniguruma/src/utf32_be.c +194 -0
  163. package/deps/jq/modules/oniguruma/src/utf32_le.c +194 -0
  164. package/deps/jq/modules/oniguruma/src/utf8.c +335 -0
  165. package/deps/jq/modules/oniguruma/test/Makefile.am +28 -0
  166. package/deps/jq/modules/oniguruma/test/testc.c +874 -0
  167. package/deps/jq/modules/oniguruma/test/testu.c +916 -0
  168. package/deps/jq/modules/oniguruma/test-driver +153 -0
  169. package/deps/jq/modules/oniguruma/windows/testc.c +869 -0
  170. package/deps/jq/scripts/crosscompile +2 -1
  171. package/deps/jq/scripts/gen_utf8_tables.py +2 -3
  172. package/deps/jq/scripts/update-website +29 -0
  173. package/deps/jq/scripts/version +7 -2
  174. package/deps/jq/sig/jq-release.key +41 -0
  175. package/deps/jq/sig/v1.3/jq-linux-x86.asc +17 -0
  176. package/deps/jq/sig/v1.3/jq-linux-x86_64.asc +17 -0
  177. package/deps/jq/sig/v1.3/jq-osx-x86.asc +17 -0
  178. package/deps/jq/sig/v1.3/jq-osx-x86_64.asc +17 -0
  179. package/deps/jq/sig/v1.3/jq-win32.exe.asc +17 -0
  180. package/deps/jq/sig/v1.3/jq-win64.exe.asc +17 -0
  181. package/deps/jq/sig/v1.3/sha256sum.txt +6 -0
  182. package/deps/jq/sig/v1.4/jq-linux-x86.asc +17 -0
  183. package/deps/jq/sig/v1.4/jq-linux-x86_64.asc +17 -0
  184. package/deps/jq/sig/v1.4/jq-osx-x86.asc +17 -0
  185. package/deps/jq/sig/v1.4/jq-osx-x86_64.asc +17 -0
  186. package/deps/jq/sig/v1.4/jq-solaris11-32.asc +17 -0
  187. package/deps/jq/sig/v1.4/jq-solaris11-64.asc +17 -0
  188. package/deps/jq/sig/v1.4/jq-win32.exe.asc +17 -0
  189. package/deps/jq/sig/v1.4/jq-win64.exe.asc +17 -0
  190. package/deps/jq/sig/v1.4/sha256sum.txt +8 -0
  191. package/deps/jq/sig/v1.5/jq-linux32-no-oniguruma.asc +17 -0
  192. package/deps/jq/sig/v1.5/jq-linux32.asc +17 -0
  193. package/deps/jq/sig/v1.5/jq-linux64.asc +17 -0
  194. package/deps/jq/sig/v1.5/jq-osx-amd64.asc +17 -0
  195. package/deps/jq/sig/v1.5/jq-win32.exe.asc +17 -0
  196. package/deps/jq/sig/v1.5/jq-win64.exe.asc +17 -0
  197. package/deps/jq/sig/v1.5/sha256sum.txt +5 -0
  198. package/deps/jq/sig/v1.5rc1/jq-linux-x86_64-static.asc +17 -0
  199. package/deps/jq/sig/v1.5rc1/jq-win32.exe.asc +17 -0
  200. package/deps/jq/sig/v1.5rc1/jq-win64.exe.asc +17 -0
  201. package/deps/jq/sig/v1.5rc1/sha256sum.txt +3 -0
  202. package/deps/jq/sig/v1.5rc2/jq-linux-x86.asc +17 -0
  203. package/deps/jq/sig/v1.5rc2/jq-linux-x86_64.asc +17 -0
  204. package/deps/jq/sig/v1.5rc2/jq-osx-x86_64.asc +17 -0
  205. package/deps/jq/sig/v1.5rc2/jq-win32.exe.asc +17 -0
  206. package/deps/jq/sig/v1.5rc2/jq-win64.exe.asc +17 -0
  207. package/deps/jq/sig/v1.5rc2/sha256sum.txt +5 -0
  208. package/deps/jq/sig/v1.6/jq-linux32.asc +16 -0
  209. package/deps/jq/sig/v1.6/jq-linux64.asc +16 -0
  210. package/deps/jq/sig/v1.6/jq-osx-amd64.asc +16 -0
  211. package/deps/jq/sig/v1.6/jq-win32.exe.asc +16 -0
  212. package/deps/jq/sig/v1.6/jq-win64.exe.asc +16 -0
  213. package/deps/jq/sig/v1.6/sha256sum.txt +5 -0
  214. package/deps/jq/{builtin.c → src/builtin.c} +449 -344
  215. package/deps/jq/{builtin.h → src/builtin.h} +0 -0
  216. package/deps/jq/src/builtin.jq +311 -0
  217. package/deps/jq/{bytecode.c → src/bytecode.c} +0 -0
  218. package/deps/jq/{bytecode.h → src/bytecode.h} +0 -0
  219. package/deps/jq/{compile.c → src/compile.c} +213 -37
  220. package/deps/jq/{compile.h → src/compile.h} +7 -2
  221. package/deps/jq/{exec_stack.h → src/exec_stack.h} +0 -0
  222. package/deps/jq/{execute.c → src/execute.c} +127 -24
  223. package/deps/jq/{inject_errors.c → src/inject_errors.c} +0 -0
  224. package/deps/jq/{jq.h → src/jq.h} +13 -2
  225. package/deps/jq/{jq_parser.h → src/jq_parser.h} +0 -0
  226. package/deps/jq/{jq_test.c → src/jq_test.c} +1 -1
  227. package/deps/jq/{jv.c → src/jv.c} +24 -5
  228. package/deps/jq/{jv.h → src/jv.h} +46 -11
  229. package/deps/jq/{jv_alloc.c → src/jv_alloc.c} +0 -0
  230. package/deps/jq/{jv_alloc.h → src/jv_alloc.h} +0 -0
  231. package/deps/jq/{jv_aux.c → src/jv_aux.c} +38 -14
  232. package/deps/jq/{jv_dtoa.c → src/jv_dtoa.c} +4 -5
  233. package/deps/jq/{jv_dtoa.h → src/jv_dtoa.h} +0 -0
  234. package/deps/jq/src/jv_file.c +81 -0
  235. package/deps/jq/{jv_parse.c → src/jv_parse.c} +8 -2
  236. package/deps/jq/{jv_print.c → src/jv_print.c} +80 -27
  237. package/deps/jq/{jv_unicode.c → src/jv_unicode.c} +28 -4
  238. package/deps/jq/{jv_unicode.h → src/jv_unicode.h} +1 -0
  239. package/deps/jq/{jv_utf8_tables.h → src/jv_utf8_tables.h} +0 -0
  240. package/deps/jq/{lexer.c → src/lexer.c} +317 -292
  241. package/deps/jq/{lexer.h → src/lexer.h} +16 -12
  242. package/deps/jq/{lexer.l → src/lexer.l} +5 -4
  243. package/deps/jq/src/libm.h +291 -0
  244. package/deps/jq/{linker.c → src/linker.c} +5 -3
  245. package/deps/jq/{linker.h → src/linker.h} +0 -0
  246. package/deps/jq/{locfile.c → src/locfile.c} +1 -1
  247. package/deps/jq/{locfile.h → src/locfile.h} +0 -0
  248. package/deps/jq/{main.c → src/main.c} +202 -100
  249. package/deps/jq/{opcode_list.h → src/opcode_list.h} +4 -0
  250. package/deps/jq/{parser.c → src/parser.c} +1149 -1069
  251. package/deps/jq/{parser.h → src/parser.h} +28 -24
  252. package/deps/jq/{parser.y → src/parser.y} +108 -52
  253. package/deps/jq/{util.c → src/util.c} +12 -9
  254. package/deps/jq/{util.h → src/util.h} +0 -0
  255. package/deps/jq/tests/base64.test +35 -0
  256. package/deps/jq/tests/base64test +5 -0
  257. package/deps/jq/tests/jq-f-test.sh +4 -0
  258. package/deps/jq/tests/jq.test +305 -21
  259. package/deps/jq/tests/jqtest +1 -1
  260. package/deps/jq/tests/mantest +1 -1
  261. package/deps/jq/tests/onig.test +13 -0
  262. package/deps/jq/tests/onigtest +1 -1
  263. package/deps/jq/tests/optional.test +20 -0
  264. package/deps/jq/tests/optionaltest +5 -0
  265. package/deps/jq/tests/setup +7 -1
  266. package/deps/jq/tests/shtest +133 -29
  267. package/deps/jq/tests/utf8-truncate.jq +3 -0
  268. package/deps/jq/tests/utf8test +10 -0
  269. package/lib/index.js +7 -1
  270. package/package.json +3 -3
  271. package/test/santiy.test.js +24 -0
  272. package/deps/jq/docs/default_manpage.md +0 -22
  273. package/deps/jq/docs/public/bootstrap/css/bootstrap-responsive.css +0 -1058
  274. package/deps/jq/docs/public/bootstrap/css/bootstrap-responsive.min.css +0 -9
  275. package/deps/jq/docs/public/bootstrap/css/bootstrap.css +0 -5224
  276. package/deps/jq/docs/public/bootstrap/css/bootstrap.min.css +0 -9
  277. package/deps/jq/docs/public/bootstrap/img/glyphicons-halflings-white.png +0 -0
  278. package/deps/jq/docs/public/bootstrap/img/glyphicons-halflings.png +0 -0
  279. package/deps/jq/docs/public/bootstrap/js/bootstrap.js +0 -2027
  280. package/deps/jq/docs/public/bootstrap/js/bootstrap.min.js +0 -6
  281. package/deps/jq/docs/templates/shared/_header.liquid +0 -26
  282. package/deps/jq/jq.1.default +0 -39
  283. package/deps/jq/jv_file.c +0 -49
  284. package/deps/jq/libm.h +0 -160
  285. package/deps/jq/setup.sh +0 -33
  286. package/reports/jest-port-api.xml +0 -35
@@ -3,8 +3,9 @@ headline: jq Manual (development version)
3
3
 
4
4
  history: |
5
5
 
6
- *For released versions, see [jq 1.4](/jq/manual/v1.4) or
7
- [jq 1.3](/jq/manual/v1.3).*
6
+ *For released versions, see [jq 1.6](/jq/manual/v1.6),
7
+ [jq 1.5](/jq/manual/v1.5), [jq 1.4](/jq/manual/v1.4)
8
+ or [jq 1.3](/jq/manual/v1.3).*
8
9
 
9
10
  body: |
10
11
 
@@ -107,7 +108,7 @@ sections:
107
108
  output and an ASCII LF (line feed) is printed after every
108
109
  output. Input JSON texts that fail to parse are ignored (but
109
110
  warned about), discarding all subsequent input until the next
110
- RS. This more also parses the output of jq without the `--seq`
111
+ RS. This mode also parses the output of jq without the `--seq`
111
112
  option.
112
113
 
113
114
  * `--stream`:
@@ -160,6 +161,9 @@ sections:
160
161
  terminal. You can force it to produce color even if writing to
161
162
  a pipe or a file using `-C`, and disable color with `-M`.
162
163
 
164
+ Colors can be configured with the `JQ_COLORS` environment
165
+ variable (see below).
166
+
163
167
  * `--ascii-output` / `-a`:
164
168
 
165
169
  jq usually outputs non-ASCII Unicode codepoints as UTF-8, even
@@ -209,6 +213,9 @@ sections:
209
213
  problem or system error, 3 if there was a jq program compile
210
214
  error, or 0 if the jq program ran.
211
215
 
216
+ Another way to set the exit status is with the `halt_error`
217
+ builtin function.
218
+
212
219
  * `--arg name value`:
213
220
 
214
221
  This option passes a value to the jq program as a predefined
@@ -217,6 +224,9 @@ sections:
217
224
  `value` will be treated as a string, so `--arg foo 123` will
218
225
  bind `$foo` to `"123"`.
219
226
 
227
+ Named arguments are also available to the jq program as
228
+ `$ARGS.named`.
229
+
220
230
  * `--argjson name JSON-text`:
221
231
 
222
232
  This option passes a JSON-encoded value to the jq program as a
@@ -227,10 +237,17 @@ sections:
227
237
 
228
238
  This option reads all the JSON texts in the named file and binds
229
239
  an array of the parsed JSON values to the given global variable.
230
- If you run jq with `--argfile foo bar`, then `$foo` is available
240
+ If you run jq with `--slurpfile foo bar`, then `$foo` is available
231
241
  in the program and has an array whose elements correspond to the
232
242
  texts in the file named `bar`.
233
243
 
244
+ * `--rawfile variable-name filename`:
245
+
246
+ This option reads in the named file and binds its contents to the given
247
+ global variable. If you run jq with `--rawfile foo bar`, then `$foo` is
248
+ available in the program and has a string whose contents are to the texs
249
+ in the file named `bar`.
250
+
234
251
  * `--argfile variable-name filename`:
235
252
 
236
253
  Do not use. Use `--slurpfile` instead.
@@ -239,6 +256,16 @@ sections:
239
256
  one text, then that is used, else an array of texts is used as
240
257
  in `--slurpfile`.)
241
258
 
259
+ * `--args`:
260
+
261
+ Remaining arguments are positional string arguments. These are
262
+ available to the jq program as `$ARGS.positional[]`.
263
+
264
+ * `--jsonargs`:
265
+
266
+ Remaining arguments are positional JSON text arguments. These
267
+ are available to the jq program as `$ARGS.positional[]`.
268
+
242
269
  * `--run-tests [filename]`:
243
270
 
244
271
  Runs the tests in the given file or standard input. This must
@@ -255,12 +282,12 @@ sections:
255
282
 
256
283
  - title: Basic filters
257
284
  entries:
258
- - title: "`.`"
285
+ - title: "Identity: `.`"
259
286
  body: |
260
287
 
261
- The absolute simplest (and least interesting) filter
262
- is `.`. This is a filter that takes its input and
263
- produces it unchanged as output.
288
+ The absolute simplest filter is `.` . This is a filter that
289
+ takes its input and produces it unchanged as output. That is,
290
+ this is the identity operator.
264
291
 
265
292
  Since jq by default pretty-prints all output, this trivial
266
293
  program can be a useful way of formatting JSON output from,
@@ -271,17 +298,24 @@ sections:
271
298
  input: '"Hello, world!"'
272
299
  output: ['"Hello, world!"']
273
300
 
274
- - title: "`.foo`, `.foo.bar`"
301
+ - title: "Object Identifier-Index: `.foo`, `.foo.bar`"
275
302
  body: |
276
303
 
277
304
  The simplest *useful* filter is `.foo`. When given a
278
305
  JSON object (aka dictionary or hash) as input, it produces
279
306
  the value at the key "foo", or null if there's none present.
280
307
 
308
+ A filter of the form `.foo.bar` is equivalent to `.foo|.bar`.
309
+
310
+ This syntax only works for simple, identifier-like keys, that
311
+ is, keys that are all made of alphanumeric characters and
312
+ underscore, and which do not start with a digit.
313
+
281
314
  If the key contains special characters, you need to surround
282
- it with double quotes like this: `."foo$"`.
315
+ it with double quotes like this: `."foo$"`, or else `.["foo$"]`.
283
316
 
284
- A filter of the form `.foo.bar` is equivalent to `.foo|.bar`.
317
+ For example `.["foo::bar"]` and `.["foo.bar"]` work while
318
+ `.foo::bar` does not, and `.foo.bar` means `.["foo"].["bar"]`.
285
319
 
286
320
  examples:
287
321
  - program: '.foo'
@@ -294,7 +328,7 @@ sections:
294
328
  input: '{"foo": 42}'
295
329
  output: [42]
296
330
 
297
- - title: "`.foo?`"
331
+ - title: "Optional Object Identifier-Index: `.foo?`"
298
332
  body: |
299
333
 
300
334
  Just like `.foo`, but does not output even an error when `.`
@@ -314,37 +348,22 @@ sections:
314
348
  input: '[1,2]'
315
349
  output: ['[]']
316
350
 
317
- - title: "`.[<string>]`, `.[2]`, `.[10:15]`"
351
+ - title: "Generic Object Index: `.[<string>]`"
318
352
  body: |
319
353
 
320
354
  You can also look up fields of an object using syntax like
321
- `.["foo"]` (.foo above is a shorthand version of this). This
322
- one works for arrays as well, if the key is an
323
- integer. Arrays are zero-based (like javascript), so `.[2]`
324
- returns the third element of the array.
325
-
326
- The `.[10:15]` syntax can be used to return a subarray of an
327
- array or substring of a string. The array returned by
328
- `.[10:15]` will be of length 5, containing the elements from
329
- index 10 (inclusive) to index 15 (exclusive). Either index may
330
- be negative (in which case it counts backwards from the end of
331
- the array), or omitted (in which case it refers to the start
332
- or end of the array).
355
+ `.["foo"]` (.foo above is a shorthand version of this, but
356
+ only for identifier-like strings).
333
357
 
334
- The `.[2]` syntax can be used to return the element at the
335
- given index. Negative indices are allowed, with -1 referring
336
- to the last element, -2 referring to the next to last element,
337
- and so on.
358
+ - title: "Array Index: `.[2]`"
359
+ body: |
338
360
 
339
- The `.foo` syntax only works for simply keys i.e. keys that
340
- are all alphanumeric characters. `.[<string>]` works with
341
- keys that contain special characters such as colons and dots.
342
- For example `.["foo::bar"]` and `.["foo.bar"]` work while
343
- `.foo::bar` and `.foo.bar` would not.
361
+ When the index value is an integer, `.[<value>]` can index
362
+ arrays. Arrays are zero-based, so `.[2]` returns the third
363
+ element.
344
364
 
345
- The `?` "operator" can also be used with the slice operator,
346
- as in `.[10:15]?`, which outputs values where the inputs are
347
- slice-able.
365
+ Negative indices are allowed, with -1 referring to the last
366
+ element, -2 referring to the next to last element, and so on.
348
367
 
349
368
  examples:
350
369
  - program: '.[0]'
@@ -355,6 +374,22 @@ sections:
355
374
  input: '[{"name":"JSON", "good":true}, {"name":"XML", "good":false}]'
356
375
  output: ['null']
357
376
 
377
+ - program: '.[-2]'
378
+ input: '[1,2,3]'
379
+ output: ['2']
380
+
381
+ - title: "Array/String Slice: `.[10:15]`"
382
+ body: |
383
+
384
+ The `.[10:15]` syntax can be used to return a subarray of an
385
+ array or substring of a string. The array returned by
386
+ `.[10:15]` will be of length 5, containing the elements from
387
+ index 10 (inclusive) to index 15 (exclusive). Either index may
388
+ be negative (in which case it counts backwards from the end of
389
+ the array), or omitted (in which case it refers to the start
390
+ or end of the array).
391
+
392
+ examples:
358
393
  - program: '.[2:4]'
359
394
  input: '["a","b","c","d","e"]'
360
395
  output: ['["c", "d"]']
@@ -371,11 +406,7 @@ sections:
371
406
  input: '["a","b","c","d","e"]'
372
407
  output: ['["d", "e"]']
373
408
 
374
- - program: '.[-2]'
375
- input: '[1,2,3]'
376
- output: ['2']
377
-
378
- - title: "`.[]`"
409
+ - title: "Array/Object Value Iterator: `.[]`"
379
410
  body: |
380
411
 
381
412
  If you use the `.[index]` syntax, but omit the index
@@ -408,15 +439,16 @@ sections:
408
439
  Like `.[]`, but no errors will be output if . is not an array
409
440
  or object.
410
441
 
411
- - title: "`,`"
442
+ - title: "Comma: `,`"
412
443
  body: |
413
444
 
414
445
  If two filters are separated by a comma, then the
415
- input will be fed into both and there will be multiple
416
- outputs: first, all of the outputs produced by the left
417
- expression, and then all of the outputs produced by the
418
- right. For instance, filter `.foo, .bar`, produces
419
- both the "foo" fields and "bar" fields as separate outputs.
446
+ same input will be fed into both and the two filters' output
447
+ value streams will be concatenated in order: first, all of the
448
+ outputs produced by the left expression, and then all of the
449
+ outputs produced by the right. For instance, filter `.foo,
450
+ .bar`, produces both the "foo" fields and "bar" fields as
451
+ separate outputs.
420
452
 
421
453
  examples:
422
454
  - program: '.foo, .bar'
@@ -431,8 +463,9 @@ sections:
431
463
  input: '["a","b","c","d","e"]'
432
464
  output: ['"e"', '"c"']
433
465
 
434
- - title: "`|`"
466
+ - title: "Pipe: `|`"
435
467
  body: |
468
+
436
469
  The | operator combines two filters by feeding the output(s) of
437
470
  the one on the left into the input of the one on the right. It's
438
471
  pretty much the same as the Unix shell's pipe, if you're used to
@@ -443,11 +476,29 @@ sections:
443
476
  expression `.[] | .foo` retrieves the "foo" field of each
444
477
  element of the input array.
445
478
 
479
+ Note that `.a.b.c` is the same as `.a | .b | .c`.
480
+
481
+ Note too that `.` is the input value at the particular stage
482
+ in a "pipeline", specifically: where the `.` expression appears.
483
+ Thus `.a | . | .b` is the same as `.a.b`, as the `.` in the
484
+ middle refers to whatever value `.a` produced.
485
+
446
486
  examples:
447
487
  - program: '.[] | .name'
448
488
  input: '[{"name":"JSON", "good":true}, {"name":"XML", "good":false}]'
449
489
  output: ['"JSON"', '"XML"']
450
490
 
491
+ - title: "Parenthesis"
492
+ body: |
493
+
494
+ Parenthesis work as a grouping operator just as in any typical
495
+ programming language.
496
+
497
+ examples:
498
+ - program: '(. + 2) * 5'
499
+ input: '1'
500
+ output: [15]
501
+
451
502
  - title: Types and Values
452
503
  body: |
453
504
 
@@ -462,16 +513,16 @@ sections:
462
513
  instead.
463
514
 
464
515
  entries:
465
- - title: Array construction - `[]`
516
+ - title: "Array construction: `[]`"
466
517
  body: |
467
518
 
468
519
  As in JSON, `[]` is used to construct arrays, as in
469
520
  `[1,2,3]`. The elements of the arrays can be any jq
470
- expression. All of the results produced by all of the
471
- expressions are collected into one big array. You can use it
472
- to construct an array out of a known quantity of values (as
473
- in `[.foo, .bar, .baz]`) or to "collect" all the results of a
474
- filter into an array (as in `[.items[].name]`)
521
+ expression, including a pipeline. All of the results produced
522
+ by all of the expressions are collected into one big array.
523
+ You can use it to construct an array out of a known quantity
524
+ of values (as in `[.foo, .bar, .baz]`) or to "collect" all the
525
+ results of a filter into an array (as in `[.items[].name]`)
475
526
 
476
527
  Once you understand the "," operator, you can look at jq's array
477
528
  syntax in a different light: the expression `[1,2,3]` is not using a
@@ -487,30 +538,37 @@ sections:
487
538
  - program: "[.user, .projects[]]"
488
539
  input: '{"user":"stedolan", "projects": ["jq", "wikiflow"]}'
489
540
  output: ['["stedolan", "jq", "wikiflow"]']
490
- - title: Objects - `{}`
541
+ - program: "[ .[] | . * 2]"
542
+ input: '[1, 2, 3]'
543
+ output: ['[2, 4, 6]']
544
+
545
+ - title: "Object Construction: `{}`"
491
546
  body: |
492
547
 
493
548
  Like JSON, `{}` is for constructing objects (aka
494
549
  dictionaries or hashes), as in: `{"a": 42, "b": 17}`.
495
550
 
496
- If the keys are "sensible" (all alphabetic characters), then
497
- the quotes can be left off. The value can be any expression
498
- (although you may need to wrap it in parentheses if it's a
499
- complicated one), which gets applied to the {} expression's
500
- input (remember, all filters have an input and an
501
- output).
551
+ If the keys are "identifier-like", then the quotes can be left
552
+ off, as in `{a:42, b:17}`. Keys generated by expressions need
553
+ to be parenthesized, e.g., `{("a"+"b"):59}`.
554
+
555
+ The value can be any expression (although you may need to
556
+ wrap it in parentheses if it's a complicated one), which gets
557
+ applied to the {} expression's input (remember, all filters
558
+ have an input and an output).
502
559
 
503
560
  {foo: .bar}
504
561
 
505
562
  will produce the JSON object `{"foo": 42}` if given the JSON
506
- object `{"bar":42, "baz":43}`. You can use this to select
507
- particular fields of an object: if the input is an object
508
- with "user", "title", "id", and "content" fields and you
509
- just want "user" and "title", you can write
563
+ object `{"bar":42, "baz":43}` as its input. You can use this
564
+ to select particular fields of an object: if the input is an
565
+ object with "user", "title", "id", and "content" fields and
566
+ you just want "user" and "title", you can write
510
567
 
511
568
  {user: .user, title: .title}
512
569
 
513
- Because that's so common, there's a shortcut syntax: `{user, title}`.
570
+ Because that is so common, there's a shortcut syntax for it:
571
+ `{user, title}`.
514
572
 
515
573
  If one of the expressions produces multiple results,
516
574
  multiple dictionaries will be produced. If the input's
@@ -545,6 +603,24 @@ sections:
545
603
  input: '{"user":"stedolan","titles":["JQ Primer", "More JQ"]}'
546
604
  output: ['{"stedolan": ["JQ Primer", "More JQ"]}']
547
605
 
606
+ - title: "Recursive Descent: `..`"
607
+ body: |
608
+
609
+ Recursively descends `.`, producing every value. This is the
610
+ same as the zero-argument `recurse` builtin (see below). This
611
+ is intended to resemble the XPath `//` operator. Note that
612
+ `..a` does not work; use `..|.a` instead. In the example
613
+ below we use `..|.a?` to find all the values of object keys
614
+ "a" in any object found "below" `.`.
615
+
616
+ This is particularly useful in conjunction with `path(EXP)`
617
+ (also see below) and the `?` operator.
618
+
619
+ examples:
620
+ - program: '..|.a?'
621
+ input: '[[{"a":1}]]'
622
+ output: ['1']
623
+
548
624
  - title: Builtin operators and functions
549
625
  body: |
550
626
 
@@ -555,7 +631,7 @@ sections:
555
631
  no result.
556
632
 
557
633
  entries:
558
- - title: Addition - `+`
634
+ - title: "Addition: `+`"
559
635
  body: |
560
636
 
561
637
  The operator `+` takes two filters, applies them both
@@ -594,7 +670,7 @@ sections:
594
670
  input: 'null'
595
671
  output: ['{"a": 42, "b": 2, "c": 3}']
596
672
 
597
- - title: Subtraction - `-`
673
+ - title: "Subtraction: `-`"
598
674
  body: |
599
675
 
600
676
  As well as normal arithmetic subtraction on numbers, the `-`
@@ -609,7 +685,7 @@ sections:
609
685
  input: '["xml", "yaml", "json"]'
610
686
  output: ['["json"]']
611
687
 
612
- - title: Multiplication, division, modulo - `*`, `/`, and `%`
688
+ - title: "Multiplication, division, modulo: `*`, `/`, and `%`"
613
689
  body: |
614
690
 
615
691
  These infix operators behave as expected when given two numbers.
@@ -619,7 +695,7 @@ sections:
619
695
  that string that many times. `"x" * 0` produces **null**.
620
696
 
621
697
  Dividing a string by another splits the first using the second
622
- as separators.
698
+ as separators.
623
699
 
624
700
  Multiplying two objects will merge them recursively: this works
625
701
  like addition but if both objects contain a value for the
@@ -662,6 +738,18 @@ sections:
662
738
  input: '[[1,2], "string", {"a":2}, null]'
663
739
  output: [2, 6, 1, 0]
664
740
 
741
+
742
+ - title: "`utf8bytelength`"
743
+ body: |
744
+
745
+ The builtin function `utf8bytelength` outputs the number of
746
+ bytes used to encode a string in UTF-8.
747
+
748
+ examples:
749
+ - program: 'utf8bytelength'
750
+ input: '"\u03bc"'
751
+ output: [2]
752
+
665
753
  - title: "`keys`, `keys_unsorted`"
666
754
  body: |
667
755
 
@@ -710,12 +798,12 @@ sections:
710
798
 
711
799
  - title: "`in`"
712
800
  body: |
713
-
714
- The builtin function `in` returns the input key is in the
801
+
802
+ The builtin function `in` returns whether or not the input key is in the
715
803
  given object, or the input index corresponds to an element
716
804
  in the given array. It is, essentially, an inversed version
717
805
  of `has`.
718
-
806
+
719
807
  examples:
720
808
  - program: '.[] | in({"foo": 42})'
721
809
  input: '["foo", "bar"]'
@@ -723,13 +811,35 @@ sections:
723
811
  - program: 'map(in([0,1]))'
724
812
  input: '[2, 0]'
725
813
  output: ['[false, true]']
726
-
814
+
815
+ - title: "`map(x)`, `map_values(x)`"
816
+ body: |
817
+
818
+ For any filter `x`, `map(x)` will run that filter for each
819
+ element of the input array, and return the outputs in a new
820
+ array. `map(.+1)` will increment each element of an array of numbers.
821
+
822
+ Similarly, `map_values(x)` will run that filter for each element,
823
+ but it will return an object when an object is passed.
824
+
825
+ `map(x)` is equivalent to `[.[] | x]`. In fact, this is how
826
+ it's defined. Similarly, `map_values(x)` is defined as `.[] |= x`.
827
+
828
+ examples:
829
+ - program: 'map(.+1)'
830
+ input: '[1,2,3]'
831
+ output: ['[2,3,4]']
832
+
833
+ - program: 'map_values(.+1)'
834
+ input: '{"a": 1, "b": 2, "c": 3}'
835
+ output: ['{"a": 2, "b": 3, "c": 4}']
836
+
727
837
  - title: "`path(path_expression)`"
728
838
  body: |
729
839
 
730
840
  Outputs array representations of the given path expression
731
- in `.`. The outputs are arrays of strings (keys in objects0
732
- and/or numbers (array indices.
841
+ in `.`. The outputs are arrays of strings (object keys)
842
+ and/or numbers (array indices).
733
843
 
734
844
  Path expressions are jq expressions like `.a`, but also `.[]`.
735
845
  There are two types of path expressions: ones that can match
@@ -770,6 +880,48 @@ sections:
770
880
  input: '["foo", "bar", "baz"]'
771
881
  output: ['["foo"]']
772
882
 
883
+ - title: "`getpath(PATHS)`"
884
+ body: |
885
+
886
+ The builtin function `getpath` outputs the values in `.` found
887
+ at each path in `PATHS`.
888
+
889
+ examples:
890
+ - program: 'getpath(["a","b"])'
891
+ input: 'null'
892
+ output: ['null']
893
+ - program: '[getpath(["a","b"], ["a","c"])]'
894
+ input: '{"a":{"b":0, "c":1}}'
895
+ output: ['[0, 1]']
896
+
897
+ - title: "`setpath(PATHS; VALUE)`"
898
+ body: |
899
+
900
+ The builtin function `setpath` sets the `PATHS` in `.` to `VALUE`.
901
+
902
+ examples:
903
+ - program: 'setpath(["a","b"]; 1)'
904
+ input: 'null'
905
+ output: ['{"a": {"b": 1}}']
906
+ - program: 'setpath(["a","b"]; 1)'
907
+ input: '{"a":{"b":0}}'
908
+ output: ['{"a": {"b": 1}}']
909
+ - program: 'setpath([0,"a"]; 1)'
910
+ input: 'null'
911
+ output: ['[{"a":1}]']
912
+
913
+ - title: "`delpaths(PATHS)`"
914
+ body: |
915
+
916
+ The builtin function `delpaths` sets the `PATHS` in `.`.
917
+ `PATHS` must be an array of paths, where each path is an array
918
+ of strings and numbers.
919
+
920
+ examples:
921
+ - program: 'delpaths([["a","b"]])'
922
+ input: '{"a":{"b":1},"x":{"y":2}}'
923
+ output: ['{"a":{},"x":{"y":2}}']
924
+
773
925
  - title: "`to_entries`, `from_entries`, `with_entries`"
774
926
  body: |
775
927
 
@@ -782,7 +934,7 @@ sections:
782
934
  `with_entries(foo)` is a shorthand for `to_entries |
783
935
  map(foo) | from_entries`, useful for doing some operation to
784
936
  all keys and values of an object. `from_entries` accepts key, Key,
785
- Name, value and Value as keys.
937
+ name, Name, value and Value as keys.
786
938
 
787
939
  examples:
788
940
  - program: 'to_entries'
@@ -848,7 +1000,25 @@ sections:
848
1000
 
849
1001
  Produces an error, just like `.a` applied to values other than
850
1002
  null and objects would, but with the given message as the
851
- error's value.
1003
+ error's value. Errors can be caught with try/catch; see below.
1004
+
1005
+ - title: "`halt`"
1006
+ body: |
1007
+
1008
+ Stops the jq program with no further outputs. jq will exit
1009
+ with exit status `0`.
1010
+
1011
+ - title: "`halt_error`, `halt_error(exit_code)`"
1012
+ body: |
1013
+
1014
+ Stops the jq program with no further outputs. The input will
1015
+ be printed on `stderr` as raw output (i.e., strings will not
1016
+ have double quotes) with no decoration, not even a newline.
1017
+
1018
+ The given `exit_code` (defaulting to `5`) will be jq's exit
1019
+ status.
1020
+
1021
+ For example, `"Error: somthing went wrong\n"|halt_error(1)`.
852
1022
 
853
1023
  - title: "`$__loc__`"
854
1024
  body: |
@@ -862,28 +1032,6 @@ sections:
862
1032
  input: 'null'
863
1033
  output: ['"{\"file\":\"<top-level>\",\"line\":1}"']
864
1034
 
865
- - title: "`map(x)`, `map_values(x)`"
866
- body: |
867
-
868
- For any filter `x`, `map(x)` will run that filter for each
869
- element of the input array, and produce the outputs a new
870
- array. `map(.+1)` will increment each element of an array of numbers.
871
-
872
- Similarly, `map_values(x)` will run that filter for each element,
873
- but it will return an object when an object is passed.
874
-
875
- `map(x)` is equivalent to `[.[] | x]`. In fact, this is how
876
- it's defined. Similarly, `map_values(x)` is defined as `.[] |= x`.
877
-
878
- examples:
879
- - program: 'map(.+1)'
880
- input: '[1,2,3]'
881
- output: ['[2,3,4]']
882
-
883
- - program: 'map_values(.+1)'
884
- input: '{"a": 1, "b": 2, "c": 3}'
885
- output: ['{"a": 2, "b": 3, "c": 4}']
886
-
887
1035
  - title: "`paths`, `paths(node_filter)`, `leaf_paths`"
888
1036
  body: |
889
1037
 
@@ -932,8 +1080,8 @@ sections:
932
1080
  body: |
933
1081
 
934
1082
  The filter `any` takes as input an array of boolean values,
935
- and produces `true` as output if any of the the elements of
936
- the array is `true`.
1083
+ and produces `true` as output if any of the elements of
1084
+ the array are `true`.
937
1085
 
938
1086
  If the input is an empty array, `any` returns `false`.
939
1087
 
@@ -958,7 +1106,7 @@ sections:
958
1106
  body: |
959
1107
 
960
1108
  The filter `all` takes as input an array of boolean values,
961
- and produces `true` as output if all of the the elements of
1109
+ and produces `true` as output if all of the elements of
962
1110
  the array are `true`.
963
1111
 
964
1112
  The `all(condition)` form applies the given condition to the
@@ -980,7 +1128,7 @@ sections:
980
1128
  input: '[]'
981
1129
  output: ["true"]
982
1130
 
983
- - title: "\\[Requires 1.5\\] `flatten`, `flatten(depth)`"
1131
+ - title: "`flatten`, `flatten(depth)`"
984
1132
  body: |
985
1133
 
986
1134
  The filter `flatten` takes as input an array of nested arrays,
@@ -1386,7 +1534,7 @@ sections:
1386
1534
  input: '[65, 66, 67]'
1387
1535
  output: ['"ABC"']
1388
1536
 
1389
- - title: "`split`"
1537
+ - title: "`split(str)`"
1390
1538
  body: |
1391
1539
 
1392
1540
  Splits an input string on the separator argument.
@@ -1404,16 +1552,22 @@ sections:
1404
1552
  running `split("foo") | join("foo")` over any input string
1405
1553
  returns said input string.
1406
1554
 
1555
+ Numbers and booleans in the input are converted to strings.
1556
+ Null values are treated as empty strings. Arrays and objects
1557
+ in the input are not supported.
1558
+
1407
1559
  examples:
1408
1560
  - program: 'join(", ")'
1409
1561
  input: '["a","b,c,d","e"]'
1410
1562
  output: ['"a, b,c,d, e"']
1411
-
1563
+ - program: 'join(" ")'
1564
+ input: '["a",1,2.3,true,null,false]'
1565
+ output: ['"a 1 2.3 true false"']
1412
1566
 
1413
1567
  - title: "`ascii_downcase`, `ascii_upcase`"
1414
1568
  body: |
1415
1569
 
1416
- Emit a copy of the input string with its alphabetic characters (a-z and A-Z)
1570
+ Emit a copy of the input string with its alphabetic characters (a-z and A-Z)
1417
1571
  converted to the specified case.
1418
1572
 
1419
1573
  example:
@@ -1522,26 +1676,48 @@ sections:
1522
1676
  - 4
1523
1677
  - 16
1524
1678
 
1525
- - title: "`..`"
1679
+ - title: "`walk(f)`"
1526
1680
  body: |
1527
1681
 
1528
- Short-hand for `recurse` without arguments. This is intended
1529
- to resemble the XPath `//` operator. Note that `..a` does not
1530
- work; use `..|a` instead. In the example below we use
1531
- `..|.a?` to find all the values of object keys "a" in any
1532
- object found "below" `.`.
1682
+ The `walk(f)` function applies f recursively to every
1683
+ component of the input entity. When an array is
1684
+ encountered, f is first applied to its elements and then to
1685
+ the array itself; when an object is encountered, f is first
1686
+ applied to all the values and then to the object. In
1687
+ practice, f will usually test the type of its input, as
1688
+ illustrated in the following examples. The first example
1689
+ highlights the usefulness of processing the elements of an
1690
+ array of arrays before processing the array itself. The second
1691
+ example shows how all the keys of all the objects within the
1692
+ input can be considered for alteration.
1533
1693
 
1534
1694
  examples:
1535
- - program: '..|.a?'
1536
- input: '[[{"a":1}]]'
1537
- output: ['1']
1695
+ - program: 'walk(if type == "array" then sort else . end)'
1696
+ input: '[[4, 1, 7], [8, 5, 2], [3, 6, 9]]'
1697
+ output:
1698
+ - '[[1,4,7],[2,5,8],[3,6,9]]'
1699
+
1700
+ - program: 'walk( if type == "object" then with_entries( .key |= sub( "^_+"; "") ) else . end )'
1701
+ input: '[ { "_a": { "__b": 2 } } ]'
1702
+ output:
1703
+ - '[{"a":{"b":2}}]'
1538
1704
 
1539
- - title: "`env`"
1705
+ - title: "`$ENV`, `env`"
1540
1706
  body: |
1541
1707
 
1542
- Outputs an object representing jq's environment.
1708
+ `$ENV` is an object representing the environment variables as
1709
+ set when the jq program started.
1710
+
1711
+ `env` outputs an object representing jq's current environment.
1712
+
1713
+ At the moment there is no builtin for setting environment
1714
+ variables.
1543
1715
 
1544
1716
  examples:
1717
+ - program: '$ENV.PAGER'
1718
+ input: 'null'
1719
+ output: ['"less"']
1720
+
1545
1721
  - program: 'env.PAGER'
1546
1722
  input: 'null'
1547
1723
  output: ['"less"']
@@ -1549,7 +1725,7 @@ sections:
1549
1725
  - title: "`transpose`"
1550
1726
  body: |
1551
1727
 
1552
- Transpose a possibly jagged matrix (an array of arrays).
1728
+ Transpose a possibly jagged matrix (an array of arrays).
1553
1729
  Rows are padded with nulls so the result is always rectangular.
1554
1730
 
1555
1731
  examples:
@@ -1664,6 +1840,11 @@ sections:
1664
1840
 
1665
1841
  The input is converted to base64 as specified by RFC 4648.
1666
1842
 
1843
+ * `@base64d`:
1844
+
1845
+ The inverse of `@base64`, input is decoded as specified by RFC 4648.
1846
+ Note\: If the decoded string is not UTF-8, the results are undefined.
1847
+
1667
1848
  This syntax can be combined with string interpolation in a
1668
1849
  useful way. You can follow a `@foo` token with a string
1669
1850
  literal. The contents of the string literal will *not* be
@@ -1693,6 +1874,14 @@ sections:
1693
1874
  input: "\"O'Hara's Ale\""
1694
1875
  output: ["\"echo 'O'\\\\''Hara'\\\\''s Ale'\""]
1695
1876
 
1877
+ - program: '@base64'
1878
+ input: '"This is a message"'
1879
+ output: ['"VGhpcyBpcyBhIG1lc3NhZ2U="']
1880
+
1881
+ - program: '@base64d'
1882
+ input: '"VGhpcyBpcyBhIG1lc3NhZ2U="'
1883
+ output: ['"This is a message"']
1884
+
1696
1885
  - title: "Dates"
1697
1886
  body: |
1698
1887
 
@@ -1716,19 +1905,25 @@ sections:
1716
1905
  the Unix epoch.
1717
1906
 
1718
1907
  Low-level jq interfaces to the C-library time functions are
1719
- also provided: `strptime`, `strftime`, `mktime`, and `gmtime`.
1720
- Refer to your host operating system's documentation for the
1721
- format strings used by `strptime` and `strftime`. Note: these
1722
- are not necessarily stable interfaces in jq, particularly as
1723
- to their localization functionality.
1908
+ also provided: `strptime`, `strftime`, `strflocaltime`,
1909
+ `mktime`, `gmtime`, and `localtime`. Refer to your host
1910
+ operating system's documentation for the format strings used
1911
+ by `strptime` and `strftime`. Note: these are not necessarily
1912
+ stable interfaces in jq, particularly as to their localization
1913
+ functionality.
1724
1914
 
1725
1915
  The `gmtime` builtin consumes a number of seconds since the
1726
1916
  Unix epoch and outputs a "broken down time" representation of
1727
- time as an array of numbers representing (in this order): the
1728
- year, the month (zero-based), the day of the month, the hour
1729
- of the day, the minute of the hour, the second of the minute,
1730
- the day of the week, and the day of the year -- all one-based
1731
- unless otherwise stated.
1917
+ Greenwhich Meridian time as an array of numbers representing
1918
+ (in this order): the year, the month (zero-based), the day of
1919
+ the month (one-based), the hour of the day, the minute of the
1920
+ hour, the second of the minute, the day of the week, and the
1921
+ day of the year -- all one-based unless otherwise stated. The
1922
+ day of the week number may be wrong on some systems for dates
1923
+ before March 1st 1900, or after December 31 2099.
1924
+
1925
+ The `localtime` builtin works like the `gmtime` builtin, but
1926
+ using the local timezone setting.
1732
1927
 
1733
1928
  The `mktime` builtin consumes "broken down time"
1734
1929
  representations of time output by `gmtime` and `strptime`.
@@ -1737,15 +1932,17 @@ sections:
1737
1932
  `fmt` argument. The output is in the "broken down time"
1738
1933
  representation consumed by `gmtime` and output by `mktime`.
1739
1934
 
1740
- The `strftime(fmt)` builtin formats a time with the given
1741
- format.
1935
+ The `strftime(fmt)` builtin formats a time (GMT) with the
1936
+ given format. The `strflocaltime` does the same, but using
1937
+ the local timezone setting.
1742
1938
 
1743
1939
  The format strings for `strptime` and `strftime` are described
1744
1940
  in typical C library documentation. The format string for ISO
1745
1941
  8601 datetime is `"%Y-%m-%dT%H:%M:%SZ"`.
1746
1942
 
1747
1943
  jq may not support some or all of this date functionality on
1748
- some systems.
1944
+ some systems. In particular, the `%u` and `%j` specifiers for
1945
+ `strptime(fmt)` are not supported on macOS.
1749
1946
 
1750
1947
  examples:
1751
1948
  - program: 'fromdate'
@@ -1760,6 +1957,54 @@ sections:
1760
1957
  input: '"2015-03-05T23:51:47Z"'
1761
1958
  output: ['1425599507']
1762
1959
 
1960
+ - title: "SQL-Style Operators"
1961
+ body: |
1962
+
1963
+ jq provides a few SQL-style operators.
1964
+
1965
+ * INDEX(stream; index_expression):
1966
+
1967
+ This builtin produces an object whose keys are computed by
1968
+ the given index expression applied to each value from the
1969
+ given stream.
1970
+
1971
+ * JOIN($idx; stream; idx_expr; join_expr):
1972
+
1973
+ This builtin joins the values from the given stream to the
1974
+ given index. The index's keys are computed by applying the
1975
+ given index expression to each value from the given stream.
1976
+ An array of the value in the stream and the corresponding
1977
+ value from the index is fed to the given join expression to
1978
+ produce each result.
1979
+
1980
+ * JOIN($idx; stream; idx_expr):
1981
+
1982
+ Same as `JOIN($idx; stream; idx_expr; .)`.
1983
+
1984
+ * JOIN($idx; idx_expr):
1985
+
1986
+ This builtin joins the input `.` to the given index, applying
1987
+ the given index expression to `.` to compute the index key.
1988
+ The join operation is as described above.
1989
+
1990
+ * IN(s):
1991
+
1992
+ This builtin outputs `true` if `.` appears in the given
1993
+ stream, otherwise it outputs `false`.
1994
+
1995
+ * IN(source; s):
1996
+
1997
+ This builtin outputs `true` if any value in the source stream
1998
+ appears in the second stream, otherwise it outputs `false`.
1999
+
2000
+ - title: "`builtins`"
2001
+ body: |
2002
+
2003
+ Returns a list of all builtin functions in the format `name/arity`.
2004
+ Since functions with the same name but different arities are considered
2005
+ separate functions, `all/0`, `all/1`, and `all/2` would all be present
2006
+ in the list.
2007
+
1763
2008
  - title: Conditionals and Comparisons
1764
2009
  entries:
1765
2010
  - title: "`==`, `!=`"
@@ -1794,9 +2039,9 @@ sections:
1794
2039
  need something more like `if (.name | length) > 0 then A else
1795
2040
  B end` instead.
1796
2041
 
1797
- If the condition A produces multiple results, it is
1798
- considered "true" if any of those results is not false or
1799
- null. If it produces zero results, it's considered false.
2042
+ If the condition `A` produces multiple results, then `B` is evaluated
2043
+ once for each result that is not false or null, and `C` is evaluated
2044
+ once for each false or null.
1800
2045
 
1801
2046
  More cases can be added to an if using `elif A then B` syntax.
1802
2047
 
@@ -1866,7 +2111,7 @@ sections:
1866
2111
  input: 'null'
1867
2112
  output: ['[false, true]']
1868
2113
 
1869
- - title: Alternative operator - `//`
2114
+ - title: "Alternative operator: `//`"
1870
2115
  body: |
1871
2116
 
1872
2117
  A filter of the form `a // b` produces the same
@@ -1943,7 +2188,7 @@ sections:
1943
2188
 
1944
2189
  because no label `$out` is visible.
1945
2190
 
1946
- - title: "`?` operator"
2191
+ - title: "Error Suppression / Optional Operator: `?`"
1947
2192
  body: |
1948
2193
 
1949
2194
  The `?` operator, used as `EXP?`, is shorthand for `try EXP`.
@@ -1996,7 +2241,7 @@ sections:
1996
2241
  evaluates to: true, true, false, false.
1997
2242
 
1998
2243
  entries:
1999
- - title: "\\[Requires 1.5\\] `test(val)`, `test(regex; flags)`"
2244
+ - title: "`test(val)`, `test(regex; flags)`"
2000
2245
  body: |
2001
2246
 
2002
2247
  Like `match`, but does not return match objects, only `true` or `false`
@@ -2010,7 +2255,7 @@ sections:
2010
2255
  input: '["xabcd", "ABC"]'
2011
2256
  output: ['true', 'true']
2012
2257
 
2013
- - title: "\\[Requires 1.5\\] `match(val)`, `match(regex; flags)`"
2258
+ - title: "`match(val)`, `match(regex; flags)`"
2014
2259
  body: |
2015
2260
 
2016
2261
  **match** outputs an object for each match it finds. Matches have
@@ -2055,7 +2300,7 @@ sections:
2055
2300
  output: [3]
2056
2301
 
2057
2302
 
2058
- - title: "\\[Requires 1.5\\] `capture(val)`, `capture(regex; flags)`"
2303
+ - title: "`capture(val)`, `capture(regex; flags)`"
2059
2304
  body: |
2060
2305
 
2061
2306
  Collects the named captures in a JSON object, with the name
@@ -2067,7 +2312,7 @@ sections:
2067
2312
  input: '"xyzzy-14"'
2068
2313
  output: ['{ "a": "xyzzy", "n": "14" }']
2069
2314
 
2070
- - title: "\\[Requires 1.5\\] `scan(regex)`, `scan(regex; flags)`"
2315
+ - title: "`scan(regex)`, `scan(regex; flags)`"
2071
2316
  body: |
2072
2317
 
2073
2318
  Emit a stream of the non-overlapping substrings of the input
@@ -2096,7 +2341,7 @@ sections:
2096
2341
  output: ['"ab","cd","ef"']
2097
2342
 
2098
2343
 
2099
- - title: "\\[Requires 1.5\\] `splits(regex)`, `splits(regex; flags)`"
2344
+ - title: "`splits(regex)`, `splits(regex; flags)`"
2100
2345
  body: |
2101
2346
 
2102
2347
  These provide the same results as their `split` counterparts,
@@ -2107,7 +2352,7 @@ sections:
2107
2352
  input: '("ab,cd", "ef, gh")'
2108
2353
  output: ['"ab"', '"cd"', '"ef"', '"gh"']
2109
2354
 
2110
- - title: "\\[Requires 1.5\\] `sub(regex; tostring)` `sub(regex; string; flags)`"
2355
+ - title: "`sub(regex; tostring)` `sub(regex; string; flags)`"
2111
2356
  body: |
2112
2357
 
2113
2358
  Emit the string obtained by replacing the first match of regex in the
@@ -2123,7 +2368,7 @@ sections:
2123
2368
  output: '"ZabcZabc"'
2124
2369
 
2125
2370
 
2126
- - title: "\\[Requires 1.5\\] `gsub(regex; string)`, `gsub(regex; string; flags)`"
2371
+ - title: "`gsub(regex; string)`, `gsub(regex; string; flags)`"
2127
2372
  body: |
2128
2373
 
2129
2374
  `gsub` is like `sub` but all the non-overlapping occurrences of the regex are
@@ -2166,7 +2411,7 @@ sections:
2166
2411
  Finally, there is a module/library system.
2167
2412
 
2168
2413
  entries:
2169
- - title: Variables
2414
+ - title: "Variable / Symbolic Binding Operator: `... as $identifier | ...`"
2170
2415
  body: |
2171
2416
 
2172
2417
  In jq, all filters have an input and an output, so manual
@@ -2266,6 +2511,52 @@ sections:
2266
2511
  input: '[[0], [0, 1], [2, 1, 0]]'
2267
2512
  output: ['{"a":0,"b":null}', '{"a":0,"b":1}', '{"a":2,"b":1}']
2268
2513
 
2514
+ - title: 'Destructuring Alternative Operator: `?//`'
2515
+ body: |
2516
+
2517
+ The destructuring alternative operator provides a concise mechanism
2518
+ for destructuring an input that can take one of several forms.
2519
+
2520
+ Suppose we have an API that returns a list of resources and events
2521
+ associated with them, and we want to get the user_id and timestamp of
2522
+ the first event for each resource. The API (having been clumsily
2523
+ converted from XML) will only wrap the events in an array if the resource
2524
+ has multiple events:
2525
+
2526
+ {"resources": [{"id": 1, "kind": "widget", "events": {"action": "create", "user_id": 1, "ts": 13}},
2527
+ {"id": 2, "kind": "widget", "events": [{"action": "create", "user_id": 1, "ts": 14}, {"action": "destroy", "user_id": 1, "ts": 15}]}]}
2528
+
2529
+ We can use the destructuring alternative operator to handle this structural change simply:
2530
+
2531
+ .resources[] as {$id, $kind, events: {$user_id, $ts}} ?// {$id, $kind, events: [{$user_id, $ts}]} | {$user_id, $kind, $id, $ts}
2532
+
2533
+ Or, if we aren't sure if the input is an array of values or an object:
2534
+
2535
+ .[] as [$id, $kind, $user_id, $ts] ?// {$id, $kind, $user_id, $ts} | ...
2536
+
2537
+ Each alternative need not define all of the same variables, but all named
2538
+ variables will be available to the subsequent expression. Variables not
2539
+ matched in the alternative that succeeded will be `null`:
2540
+
2541
+ .resources[] as {$id, $kind, events: {$user_id, $ts}} ?// {$id, $kind, events: [{$first_user_id, $first_ts}]} | {$user_id, $first_user_id, $kind, $id, $ts, $first_ts}
2542
+
2543
+ Additionally, if the subsequent expression returns an error, the
2544
+ alternative operator will attempt to try the next binding. Errors
2545
+ that occur during the final alternative are passed through.
2546
+
2547
+ [[3]] | .[] as [$a] ?// [$b] | if $a != null then error("err: \($a)") else {$a,$b} end
2548
+
2549
+ examples:
2550
+ - program: '.[] as {$a, $b, c: {$d, $e}} ?// {$a, $b, c: [{$d, $e}]} | {$a, $b, $d, $e}'
2551
+ input: '[{"a": 1, "b": 2, "c": {"d": 3, "e": 4}}, {"a": 1, "b": 2, "c": [{"d": 3, "e": 4}]}]'
2552
+ output: ['{"a":1,"b":2,"d":3,"e":4}', '{"a":1,"b":2,"d":3,"e":4}']
2553
+ - program: '.[] as {$a, $b, c: {$d}} ?// {$a, $b, c: [{$e}]} | {$a, $b, $d, $e}'
2554
+ input: '[{"a": 1, "b": 2, "c": {"d": 3, "e": 4}}, {"a": 1, "b": 2, "c": [{"d": 3, "e": 4}]}]'
2555
+ output: ['{"a":1,"b":2,"d":3,"e":null}', '{"a":1,"b":2,"d":null,"e":4}']
2556
+ - program: '.[] as [$a] ?// [$b] | if $a != null then error("err: \($a)") else {$a,$b} end'
2557
+ input: '[[3]]'
2558
+ output: ['{"a":null,"b":3}']
2559
+
2269
2560
  - title: 'Defining Functions'
2270
2561
  body: |
2271
2562
 
@@ -2274,17 +2565,17 @@ sections:
2274
2565
  def increment: . + 1;
2275
2566
 
2276
2567
  From then on, `increment` is usable as a filter just like a
2277
- builtin function (in fact, this is how some of the builtins
2568
+ builtin function (in fact, this is how many of the builtins
2278
2569
  are defined). A function may take arguments:
2279
2570
 
2280
2571
  def map(f): [.[] | f];
2281
2572
 
2282
- Arguments are passed as filters, not as values. The
2283
- same argument may be referenced multiple times with
2284
- different inputs (here `f` is run for each element of the
2285
- input array). Arguments to a function work more like
2286
- callbacks than like value arguments. This is important to
2287
- understand. Consider:
2573
+ Arguments are passed as _filters_ (functions with no
2574
+ arguments), _not_ as values. The same argument may be
2575
+ referenced multiple times with different inputs (here `f` is
2576
+ run for each element of the input array). Arguments to a
2577
+ function work more like callbacks than like value arguments.
2578
+ This is important to understand. Consider:
2288
2579
 
2289
2580
  def foo(f): f|f;
2290
2581
  5|foo(.*2)
@@ -2305,12 +2596,16 @@ sections:
2305
2596
  def addvalue($f): ...;
2306
2597
 
2307
2598
  With either definition, `addvalue(.foo)` will add the current
2308
- input's `.foo` field to each element of the array.
2599
+ input's `.foo` field to each element of the array. Do note
2600
+ that calling `addvalue(.[])` will cause the `map(. + $f)` part
2601
+ to be evaluated once per value in the value of `.` at the call
2602
+ site.
2309
2603
 
2310
2604
  Multiple definitions using the same function name are allowed.
2311
2605
  Each re-definition replaces the previous one for the same
2312
2606
  number of function arguments, but only for references from
2313
2607
  functions (or main program) subsequent to the re-definition.
2608
+ See also the section below on scoping.
2314
2609
 
2315
2610
  examples:
2316
2611
  - program: 'def addvalue(f): . + [f]; map(addvalue(.[0]))'
@@ -2320,6 +2615,23 @@ sections:
2320
2615
  input: '[[1,2],[10,20]]'
2321
2616
  output: ['[[1,2,1,2], [10,20,1,2]]']
2322
2617
 
2618
+ - title: 'Scoping'
2619
+ body: |
2620
+
2621
+ There are two types of symbols in jq: value bindings (a.k.a.,
2622
+ "variables"), and functions. Both are scoped lexically,
2623
+ with expressions being able to refer only to symbols that
2624
+ have been defined "to the left" of them. The only exception
2625
+ to this rule is that functions can refer to themselves so as
2626
+ to be able to create recursive functions.
2627
+
2628
+ For example, in the following expression there is a binding
2629
+ which is visible "to the right" of it, `... | .*3 as
2630
+ $times_three | [. + $times_three] | ...`, but not "to the
2631
+ left". Consider this expression now, `... | (.*3 as
2632
+ $times_three | [.+ $times_three]) | ...`: here the binding
2633
+ `$times_three` is _not_ visible past the closing parenthesis.
2634
+
2323
2635
  - title: Reduce
2324
2636
  body: |
2325
2637
 
@@ -2343,6 +2655,16 @@ sections:
2343
2655
  input: '[10,2,5,3]'
2344
2656
  output: ['20']
2345
2657
 
2658
+ - title: "`isempty(exp)`"
2659
+ body: |
2660
+
2661
+ Returns true if `exp` produces no outputs, false otherwise.
2662
+
2663
+ examples:
2664
+ - program: 'isempty(empty)'
2665
+ input: 'null'
2666
+ output: ['true']
2667
+
2346
2668
  - title: "`limit(n; exp)`"
2347
2669
  body: |
2348
2670
 
@@ -2494,13 +2816,30 @@ sections:
2494
2816
  that take a single input argument (e.g., `sin()`) are available as
2495
2817
  zero-argument jq functions. C math functions that take two input
2496
2818
  arguments (e.g., `pow()`) are available as two-argument jq
2497
- functions that ignore `.`.
2819
+ functions that ignore `.`. C math functions that take three input
2820
+ arguments are available as three-argument jq functions that ignore
2821
+ `.`.
2498
2822
 
2499
2823
  Availability of standard math functions depends on the
2500
2824
  availability of the corresponding math functions in your operating
2501
2825
  system and C math library. Unavailable math functions will be
2502
2826
  defined but will raise an error.
2503
2827
 
2828
+ One-input C math functions: `acos` `acosh` `asin` `asinh` `atan`
2829
+ `atanh` `cbrt` `ceil` `cos` `cosh` `erf` `erfc` `exp` `exp10`
2830
+ `exp2` `expm1` `fabs` `floor` `gamma` `j0` `j1` `lgamma` `log`
2831
+ `log10` `log1p` `log2` `logb` `nearbyint` `pow10` `rint` `round`
2832
+ `significand` `sin` `sinh` `sqrt` `tan` `tanh` `tgamma` `trunc`
2833
+ `y0` `y1`.
2834
+
2835
+ Two-input C math functions: `atan2` `copysign` `drem` `fdim`
2836
+ `fmax` `fmin` `fmod` `frexp` `hypot` `jn` `ldexp` `modf`
2837
+ `nextafter` `nexttoward` `pow` `remainder` `scalb` `scalbln` `yn`.
2838
+
2839
+ Three-input C math functions: `fma`.
2840
+
2841
+ See your system's manual for more information on each of these.
2842
+
2504
2843
  - title: 'I/O'
2505
2844
  body: |
2506
2845
 
@@ -2511,11 +2850,17 @@ sections:
2511
2850
  jq itself. These two builtins, and jq's own reading actions, can
2512
2851
  be interleaved with each other.
2513
2852
 
2514
- One builtin provides minimal output capabilities, `debug`.
2515
- (Recall that a jq program's output values are always output as
2516
- JSON texts on `stdout`.) The `debug` builtin can have
2853
+ Two builtins provide minimal output capabilities, `debug`, and
2854
+ `stderr`. (Recall that a jq program's output values are always
2855
+ output as JSON texts on `stdout`.) The `debug` builtin can have
2517
2856
  application-specific behavior, such as for executables that use
2518
- the libjq C API but aren't the jq executable itself.
2857
+ the libjq C API but aren't the jq executable itself. The `stderr`
2858
+ builtin outputs its input in raw mode to stder with no additional
2859
+ decoration, not even a newline.
2860
+
2861
+ Most jq builtins are referentially transparent, and yield constant
2862
+ and repeatable value streams when applied to constant inputs.
2863
+ This is not true of I/O builtins.
2519
2864
 
2520
2865
  entries:
2521
2866
  - title: "`input`"
@@ -2539,6 +2884,12 @@ sections:
2539
2884
  `["DEBUG:", <input-value>]` and prints that and a newline on
2540
2885
  stderr, compactly. This may change in the future.
2541
2886
 
2887
+ - title: "`stderr`"
2888
+ body: |
2889
+
2890
+ Prints its input in raw and compact mode to stderr with no
2891
+ additional decoration, not even a newline.
2892
+
2542
2893
  - title: "`input_filename`"
2543
2894
  body: |
2544
2895
 
@@ -2562,11 +2913,11 @@ sections:
2562
2913
 
2563
2914
  However, streaming isn't easy to deal with as the jq program will
2564
2915
  have `[<path>, <leaf-value>]` (and a few other forms) as inputs.
2565
-
2916
+
2566
2917
  Several builtins are provided to make handling streams easier.
2567
2918
 
2568
- The examples below use the the streamed form of `[0,[1]]`, which
2569
- is `[[0],0],[[1,0],1],[[1,0]],[[1]]`.
2919
+ The examples below use the streamed form of `[0,[1]]`, which is
2920
+ `[[0],0],[[1,0],1],[[1,0]],[[1]]`.
2570
2921
 
2571
2922
  Streaming forms include `[<path>, <leaf-value>]` (to indicate any
2572
2923
  scalar value, empty array, or empty object), and `[<path>]` (to
@@ -2610,7 +2961,6 @@ sections:
2610
2961
 
2611
2962
  - title: Assignment
2612
2963
  body: |
2613
-
2614
2964
  Assignment works a little differently in jq than in most
2615
2965
  programming languages. jq doesn't distinguish between references
2616
2966
  to and copies of something - two objects or arrays are either
@@ -2619,74 +2969,51 @@ sections:
2619
2969
 
2620
2970
  If an object has two fields which are arrays, `.foo` and `.bar`,
2621
2971
  and you append something to `.foo`, then `.bar` will not get
2622
- bigger. Even if you've just set `.bar = .foo`. If you're used to
2623
- programming in languages like Python, Java, Ruby, Javascript,
2624
- etc. then you can think of it as though jq does a full deep copy
2625
- of every object before it does the assignment (for performance,
2626
- it doesn't actually do that, but that's the general idea).
2972
+ bigger, even if you've previously set `.bar = .foo`. If you're
2973
+ used to programming in languages like Python, Java, Ruby,
2974
+ Javascript, etc. then you can think of it as though jq does a full
2975
+ deep copy of every object before it does the assignment (for
2976
+ performance it doesn't actually do that, but that's the general
2977
+ idea).
2978
+
2979
+ This means that it's impossible to build circular values in jq
2980
+ (such as an array whose first element is itself). This is quite
2981
+ intentional, and ensures that anything a jq program can produce
2982
+ can be represented in JSON.
2627
2983
 
2628
2984
  All the assignment operators in jq have path expressions on the
2629
- left-hand side.
2630
-
2631
- entries:
2632
- - title: "`=`"
2633
- body: |
2634
-
2635
- The filter `.foo = 1` will take as input an object
2636
- and produce as output an object with the "foo" field set to
2637
- 1. There is no notion of "modifying" or "changing" something
2638
- in jq - all jq values are immutable. For instance,
2639
-
2640
- .foo = .bar | .foo.baz = 1
2641
-
2642
- will not have the side-effect of setting .bar.baz to be set
2643
- to 1, as the similar-looking program in Javascript, Python,
2644
- Ruby or other languages would. Unlike these languages (but
2645
- like Haskell and some other functional languages), there is
2646
- no notion of two arrays or objects being "the same array" or
2647
- "the same object". They can be equal, or not equal, but if
2648
- we change one of them in no circumstances will the other
2649
- change behind our backs.
2650
-
2651
- This means that it's impossible to build circular values in
2652
- jq (such as an array whose first element is itself). This is
2653
- quite intentional, and ensures that anything a jq program
2654
- can produce can be represented in JSON.
2655
-
2656
- Note that the left-hand side of '=' refers to a value in `.`.
2657
- Thus `$var.foo = 1` won't work as expected (`$var.foo` is not
2658
- a valid or useful path expression in `.`); use `$var | .foo =
2659
- 1` instead.
2660
-
2661
- If the right-hand side of '=' produces multiple values, then
2662
- for each such value jq will set the paths on the left-hand
2663
- side to the value and then it will output the modified `.`.
2664
- For example, `(.a,.b)=range(2)` outputs `{"a":0,"b":0}`, then
2665
- `{"a":1,"b":1}`. The "update" assignment forms (see below) do
2666
- not do this.
2985
+ left-hand side (LHS). The right-hand side (RHS) provides values
2986
+ to set to the paths named by the LHS path expressions.
2667
2987
 
2668
- Note too that `.a,.b=0` does not set `.a` and `.b`, but
2669
- `(.a,.b)=0` sets both.
2988
+ Values in jq are always immutable. Internally, assignment works
2989
+ by using a reduction to compute new, replacement values for `.` that
2990
+ have had all the desired assignments applied to `.`, then
2991
+ outputting the modified value. This might be made clear by this
2992
+ example: `{a:{b:{c:1}}} | (.a.b|=3), .`. This will output
2993
+ `{"a":{"b":3}}` and `{"a":{"b":{"c":1}}}` because the last
2994
+ sub-expression, `.`, sees the original value, not the modified
2995
+ value.
2670
2996
 
2671
- - title: "`|=`"
2672
- body: |
2673
- As well as the assignment operator '=', jq provides the "update"
2674
- operator '|=', which takes a filter on the right-hand side and
2675
- works out the new value for the property of `.` being assigned
2676
- to by running the old value through this expression. For
2677
- instance, .foo |= .+1 will build an object with the "foo"
2678
- field set to the input's "foo" plus 1.
2997
+ Most users will want to use modification assignment operators,
2998
+ such as `|=` or `+=`, rather than `=`.
2679
2999
 
2680
- This example should show the difference between '=' and '|=':
3000
+ Note that the LHS of assignment operators refers to a value in
3001
+ `.`. Thus `$var.foo = 1` won't work as expected (`$var.foo` is
3002
+ not a valid or useful path expression in `.`); use `$var | .foo =
3003
+ 1` instead.
2681
3004
 
2682
- Provide input '{"a": {"b": 10}, "b": 20}' to the programs:
3005
+ Note too that `.a,.b=0` does not set `.a` and `.b`, but
3006
+ `(.a,.b)=0` sets both.
2683
3007
 
2684
- .a = .b
2685
- .a |= .b
2686
-
2687
- The former will set the "a" field of the input to the "b" field of the
2688
- input, and produce the output {"a": 20}. The latter will set the "a"
2689
- field of the input to the "a" field's "b" field, producing {"a": 10}.
3008
+ entries:
3009
+ - title: "Update-assignment: `|=`"
3010
+ body: |
3011
+ This is the "update" operator '|='. It takes a filter on the
3012
+ right-hand side and works out the new value for the property
3013
+ of `.` being assigned to by running the old value through this
3014
+ expression. For instance, (.foo, .bar) |= .+1 will build an
3015
+ object with the "foo" field set to the input's "foo" plus 1,
3016
+ and the "bar" field set to the input's "bar" plus 1.
2690
3017
 
2691
3018
  The left-hand side can be any general path expression; see `path()`.
2692
3019
 
@@ -2695,26 +3022,70 @@ sections:
2695
3022
  not a valid or useful path expression in `.`); use `$var |
2696
3023
  .foo |= . + 1` instead.
2697
3024
 
2698
- If the right-hand side outputs multiple values, only the last
2699
- one will be used.
3025
+ If the right-hand side outputs no values (i.e., `empty`), then
3026
+ the left-hand side path will be deleted, as with `del(path)`.
2700
3027
 
2701
- examples:
3028
+ If the right-hand side outputs multiple values, only the first
3029
+ one will be used (COMPATIBILITY NOTE: in jq 1.5 and earlier
3030
+ releases, it used to be that only the last one was used).
2702
3031
 
3032
+ examples:
2703
3033
  - program: '(..|select(type=="boolean")) |= if . then 1 else 0 end'
2704
3034
  input: '[true,false,[5,true,[true,[false]],false]]'
2705
3035
  output: ['[1,0,[5,1,[1,[0]],0]]']
2706
3036
 
2707
- - title: "`+=`, `-=`, `*=`, `/=`, `%=`, `//=`"
3037
+ - title: "Arithmetic update-assignment: `+=`, `-=`, `*=`, `/=`, `%=`, `//=`"
2708
3038
  body: |
2709
3039
 
2710
3040
  jq has a few operators of the form `a op= b`, which are all
2711
- equivalent to `a |= . op b`. So, `+= 1` can be used to increment values.
3041
+ equivalent to `a |= . op b`. So, `+= 1` can be used to
3042
+ increment values, being the same as `|= . + 1`.
2712
3043
 
2713
3044
  examples:
2714
3045
  - program: .foo += 1
2715
3046
  input: '{"foo": 42}'
2716
3047
  output: ['{"foo": 43}']
2717
3048
 
3049
+ - title: "Plain assignment: `=`"
3050
+ body: |
3051
+
3052
+ This is the plain assignment operator. Unlike the others, the
3053
+ input to the right-hand-side (RHS) is the same as the input to
3054
+ the left-hand-side (LHS) rather than the value at the LHS
3055
+ path, and all values output by the RHS will be used (as shown
3056
+ below).
3057
+
3058
+ If the RHS of '=' produces multiple values, then for each such
3059
+ value jq will set the paths on the left-hand side to the value
3060
+ and then it will output the modified `.`. For example,
3061
+ `(.a,.b)=range(2)` outputs `{"a":0,"b":0}`, then
3062
+ `{"a":1,"b":1}`. The "update" assignment forms (see above) do
3063
+ not do this.
3064
+
3065
+ This example should show the difference between '=' and '|=':
3066
+
3067
+ Provide input '{"a": {"b": 10}, "b": 20}' to the programs:
3068
+
3069
+ .a = .b
3070
+
3071
+ .a |= .b
3072
+
3073
+ The former will set the "a" field of the input to the "b"
3074
+ field of the input, and produce the output {"a": 20, "b": 20}.
3075
+ The latter will set the "a" field of the input to the "a"
3076
+ field's "b" field, producing {"a": 10, "b": 20}.
3077
+
3078
+ Another example of the difference between '=' and '|=':
3079
+
3080
+ null|(.a,.b)=range(3)
3081
+
3082
+ outputs '{"a":0,"b":0}', '{"a":1,"b":1}', and '{"a":2,"b":2}',
3083
+ while
3084
+
3085
+ null|(.a,.b)|=range(3)
3086
+
3087
+ outputs just '{"a":0,"b":0}'.
3088
+
2718
3089
  - title: Complex assignments
2719
3090
  body: |
2720
3091
  Lots more things are allowed on the left-hand side of a jq assignment
@@ -2815,7 +3186,7 @@ sections:
2815
3186
  this time jq only uses the "search" key/value of the metadata.
2816
3187
  The metadata is also made available to users via the
2817
3188
  `modulemeta` builtin.
2818
-
3189
+
2819
3190
  The "search" key in the metadata, if present, should have a
2820
3191
  string or array value (array of strings); this is the search
2821
3192
  path to be prefixed to the top-level search path.
@@ -2848,7 +3219,7 @@ sections:
2848
3219
  this time jq only uses the "search" key/value of the metadata.
2849
3220
  The metadata is also made available to users via the
2850
3221
  `modulemeta` builtin.
2851
-
3222
+
2852
3223
  The "search" key in the metadata, if present, should have a
2853
3224
  string or array value (array of strings); this is the search
2854
3225
  path to be prefixed to the top-level search path.
@@ -2876,3 +3247,42 @@ sections:
2876
3247
  could then use to, for example, search for, download, and
2877
3248
  install missing dependencies.
2878
3249
 
3250
+ - title: Colors
3251
+ body: |
3252
+
3253
+ To configure alternative colors just set the `JQ_COLORS`
3254
+ environment variable to colon-delimited list of partial terminal
3255
+ escape sequences like `"1;31"`, in this order:
3256
+
3257
+ - color for `null`
3258
+ - color for `false`
3259
+ - color for `true`
3260
+ - color for numbers
3261
+ - color for strings
3262
+ - color for arrays
3263
+ - color for objects
3264
+
3265
+ The default color scheme is the same as setting
3266
+ `"JQ_COLORS=1;30:0;39:0;39:0;39:0;32:1;39:1;39"`.
3267
+
3268
+ This is not a manual for VT100/ANSI escapes. However, each of
3269
+ these color specifications should consist of two numbers separated
3270
+ by a semi-colon, where the first number is one of these:
3271
+
3272
+ - 1 (bright)
3273
+ - 2 (dim)
3274
+ - 4 (underscore)
3275
+ - 5 (blink)
3276
+ - 7 (reverse)
3277
+ - 8 (hidden)
3278
+
3279
+ and the second is one of these:
3280
+
3281
+ - 30 (black)
3282
+ - 31 (red)
3283
+ - 32 (green)
3284
+ - 33 (yellow)
3285
+ - 34 (blue)
3286
+ - 35 (magenta)
3287
+ - 36 (cyan)
3288
+ - 37 (white)