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 JQjq filters run on a stream of JSON data. 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.But 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. Generally, things that would be done with loops and iteration in other languages are just done by gluing filters together in jq.It's important to remember that every filter has an input and an output. Piping that filter into a second runs the second filter for each element of the 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.Filters 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.Some filters produce multiple results, for instance there's one that produces all the elements of its input array. FILTERSA jq program is a "filter": it takes an input, and produces an output. The filter is written in the jq language and specifies how to transform the input file or document. One or more files may be specified, in which case jq will read input from those instead.The options are described in the INVOKING JQ section they mostly concern input and output formatting. Whitespace is only needed to separate entities such as 1 and 2, and true and false. jq can accept text input as well, but by default, jq reads a stream of JSON entities (including numbers and other literals) from stdin. For instance, running the command jq 'map(.price) | add' will take an array of JSON objects as input and return the sum of their "price" fields. Index NAME jq - Command-line JSON processor SYNOPSIS jq filter jq can transform JSON in various ways, by selecting, iterating, reducing and otherwise mangling JSON documents.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |