Output the jq version and exit with zero. You can affect how jq reads and writes its input and output using some command-line options: When using the Windows command shell (cmd.exe) it's best to use double quotes around your jq program when given on the command-line (instead of the -f program-file option), but then double-quotes in the jq program need backslash escaping. "foo" will fail on most Unix shells because that will be the same as jq foo, which will generally fail because foo is notĭefined. As a general rule it's best to always quote (with single-quote characters) the jq program, as too many characters with special meaning to jq are also shell meta-characters. Note: it is important to mind the shell's quoting rules. The output(s) of the filter are written to standard out, again as a sequence of whitespace-separated JSON data. The input to jq is parsed as a sequence of whitespace-separated JSON values which are passed through the provided filter one at a time. :) Let's start with something simpler: Invoking jq So, you can implement an averaging filter as add / length - feeding the input array both to the add filter and the length filter and then performing the division.īut that's getting ahead of ourselves. Operations that combine two filters, like addition, generally feed the same input to both and combine the results. Even literals like "hello" or 42 are filters - they take an input but always produce the same literal as output. It's important to remember that every filter has an input and an output. Generally, things that would be done with loops and iteration in other languages are just done by gluing filters together in jq. Piping that filter into a second runs the second filter for each element of the array. Some filters produce multiple results, for instance there's one that produces all the elements of its input array. There are a lot of builtin filters for extracting a particular field of an object, or converting a number to a string, or various other standard tasks.įilters can be combined in various ways - you can pipe the output of one filter into another filter, or collect the output of a filter into an array. The manual for the development version of jq can be found here.Ī jq program is a "filter": it takes an input, and produces an output.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |