From: David Tolnay Date: Fri, 14 Aug 2015 05:33:37 +0000 (-0700) Subject: Remove all trailing whitespace X-Git-Tag: jq-1.6rc1~226 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0f419563ea6fe7003bb22a654f580be963222525;p=jq Remove all trailing whitespace --- diff --git a/AUTHORS b/AUTHORS index dda9b01..dcaf7b4 100644 --- a/AUTHORS +++ b/AUTHORS @@ -18,7 +18,7 @@ Filippo Valsorda - recursive object merge ( Jack Pearkes - update tutorial Jingwen Owen Ou - jqplay.org and link to it Joe Littlejohn - bug fixes -Juan Guerrero - bug fixes +Juan Guerrero - bug fixes Kenny Shen - doc fixes Lee Thompson - autoconf stuff Markus Lanthaler - doc fixes diff --git a/COPYING b/COPYING index 03b0f56..6026d7f 100644 --- a/COPYING +++ b/COPYING @@ -30,9 +30,9 @@ license, which can be found at: The documentation website includes a copy of Twitter's Boostrap and relies on Bonsai, Liquid templates and various other projects, look them up for detailed licensing conditions. - - + + jq incorporates David M. Gay's dtoa.c and g_fmt.c, which bear the following notices: diff --git a/Makefile.am b/Makefile.am index c3a771f..6acb720 100644 --- a/Makefile.am +++ b/Makefile.am @@ -26,7 +26,7 @@ lexer.c: lexer.l $(AM_V_LEX) flex -o lexer.c --header-file=lexer.h $< lexer.h: lexer.c else -BUILT_SOURCES = +BUILT_SOURCES = .y.c: $(AM_V_YACC) echo "NOT building parser.c!" .l.c: @@ -146,7 +146,7 @@ DOC_FILES = docs/content docs/public docs/templates docs/site.yml \ docs/default_manpage.md jq.1.default # setup is only used by distribution developers, not package developers. -# Still, as a matter of allowing patching, its not a bad idea to distribute +# Still, as a matter of allowing patching, its not a bad idea to distribute # the developer setup script in the tarball. EXTRA_DIST = $(man_MANS) $(TESTS) $(TEST_LOG_COMPILER) jq.spec \ $(DOC_FILES) scripts/version parser.h parser.c lexer.h \ @@ -164,7 +164,7 @@ EXTRA_DIST = $(man_MANS) $(TESTS) $(TEST_LOG_COMPILER) jq.spec \ jq.1.prebuilt -# README.md is expected in Github projects, good stuff in it, so we'll +# README.md is expected in Github projects, good stuff in it, so we'll # distribute it and install it with the package in the doc directory. docdir = ${datadir}/doc/${PACKAGE} dist_doc_DATA = README.md COPYING AUTHORS README @@ -187,7 +187,7 @@ dist-clean-local: clean-local-docs: if ENABLE_DOCS rm -f jq.1 -endif +endif clean-local-gcov: rm -f *.gcno *.gcda *.gcov diff --git a/configure.ac b/configure.ac index d9057e3..122887a 100644 --- a/configure.ac +++ b/configure.ac @@ -200,7 +200,7 @@ AC_LINK_IFELSE([AC_LANG_SOURCE([ static __thread int x ; int main () { x = 123; return x; } ])], have___thread=yes) -if test $have___thread = yes; then +if test $have___thread = yes; then AC_DEFINE([HAVE___THREAD],1,[Define to 1 if the system supports __thread]) fi AC_MSG_RESULT($have___thread) diff --git a/docs/Rakefile b/docs/Rakefile index 167ee87..8fba5a9 100644 --- a/docs/Rakefile +++ b/docs/Rakefile @@ -19,7 +19,7 @@ module ExtraFilters def json(input) input.to_json end - + def unique(input) @n = (@n || 0) + 1 input + @n.to_s @@ -32,15 +32,15 @@ Liquid::Template.register_filter(ExtraFilters) task :serve do begin Bonsai.log "Press Control+C to quit" - + require 'rack' require 'sinatra' require 'watch' require 'launchy' - + Bonsai.root_dir = Dir.pwd - - server = fork { + + server = fork { app = Rack::Builder.app { map "/jq" do use Bonsai::StaticPassThrough, :root => Bonsai.root_dir + "/output", :urls => ["/"] @@ -50,7 +50,7 @@ task :serve do Rack::Handler.default.run(app, :Port => 5000) do Launchy.open("http://localhost:5000/jq/") end - } + } Watch.new("{content,templates,public}/**/*") { Bonsai::Exporter.process! } rescue Interrupt Process.kill("QUIT", server) @@ -96,7 +96,7 @@ task :manpage do f.puts manual['manpage_intro'] f.puts manual['body'] manual['sections'].each do |section| - + f.puts "## #{section['title'].upcase}\n" f.puts section['body'] f.puts "" @@ -116,7 +116,7 @@ task :manpage do f.puts manual['manpage_epilogue'] f.close puts Ronn::Document.new(f.path).convert('roff').gsub(/<\/?code>/,"") - end + end end task :manpage_default => ["default_manpage.md"] do diff --git a/docs/content/2.download/default.yml b/docs/content/2.download/default.yml index e96986d..a88ced0 100644 --- a/docs/content/2.download/default.yml +++ b/docs/content/2.download/default.yml @@ -15,7 +15,7 @@ body: ### Linux - + * jq 1.4 is in the official [Debian](http://packages.debian.org/jq) and [Ubuntu](http://packages.ubuntu.com/jq) repositories. Install using `sudo apt-get install jq`. @@ -126,7 +126,7 @@ body: 1.5, neither is required if you use `./configure --disable-maintainer-mode` instead of `./configure`. This flag says to use the pre-generated lexer and parser that come with the code. - + #### Building the documentation jq's documentation is compiled into static HTML using diff --git a/docs/content/3.manual/manual.yml b/docs/content/3.manual/manual.yml index 8ac564c..67ef47f 100644 --- a/docs/content/3.manual/manual.yml +++ b/docs/content/3.manual/manual.yml @@ -619,7 +619,7 @@ sections: that string that many times. `"x" * 0` produces **null**. Dividing a string by another splits the first using the second - as separators. + as separators. Multiplying two objects will merge them recursively: this works like addition but if both objects contain a value for the @@ -710,12 +710,12 @@ sections: - title: "`in`" body: | - + The builtin function `in` returns the input key is in the given object, or the input index corresponds to an element in the given array. It is, essentially, an inversed version of `has`. - + examples: - program: '.[] | in({"foo": 42})' input: '["foo", "bar"]' @@ -723,7 +723,7 @@ sections: - program: 'map(in([0,1]))' input: '[2, 0]' output: ['[false, true]'] - + - title: "`path(path_expression)`" body: | @@ -868,10 +868,10 @@ sections: For any filter `x`, `map(x)` will run that filter for each element of the input array, and produce the outputs a new array. `map(.+1)` will increment each element of an array of numbers. - + Similarly, `map_values(x)` will run that filter for each element, but it will return an object when an object is passed. - + `map(x)` is equivalent to `[.[] | x]`. In fact, this is how it's defined. Similarly, `map_values(x)` is defined as `.[] |= x`. @@ -879,7 +879,7 @@ sections: - program: 'map(.+1)' input: '[1,2,3]' output: ['[2,3,4]'] - + - program: 'map_values(.+1)' input: '{"a": 1, "b": 2, "c": 3}' output: ['{"a": 2, "b": 3, "c": 4}'] @@ -1413,7 +1413,7 @@ sections: - title: "`ascii_downcase`, `ascii_upcase`" body: | - Emit a copy of the input string with its alphabetic characters (a-z and A-Z) + Emit a copy of the input string with its alphabetic characters (a-z and A-Z) converted to the specified case. example: @@ -1576,7 +1576,7 @@ sections: - title: "`transpose`" body: | - Transpose a possibly jagged matrix (an array of arrays). + Transpose a possibly jagged matrix (an array of arrays). Rows are padded with nulls so the result is always rectangular. examples: @@ -2589,7 +2589,7 @@ sections: However, streaming isn't easy to deal with as the jq program will have `[, ]` (and a few other forms) as inputs. - + Several builtins are provided to make handling streams easier. The examples below use the the streamed form of `[0,[1]]`, which @@ -2842,7 +2842,7 @@ sections: this time jq only uses the "search" key/value of the metadata. The metadata is also made available to users via the `modulemeta` builtin. - + The "search" key in the metadata, if present, should have a string or array value (array of strings); this is the search path to be prefixed to the top-level search path. @@ -2875,7 +2875,7 @@ sections: this time jq only uses the "search" key/value of the metadata. The metadata is also made available to users via the `modulemeta` builtin. - + The "search" key in the metadata, if present, should have a string or array value (array of strings); this is the search path to be prefixed to the top-level search path. diff --git a/docs/content/3.manual/v1.3/manual.yml b/docs/content/3.manual/v1.3/manual.yml index 0f48145..a6cc436 100644 --- a/docs/content/3.manual/v1.3/manual.yml +++ b/docs/content/3.manual/v1.3/manual.yml @@ -16,7 +16,7 @@ body: | 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. Piping that filter into a second runs the second filter for each element of the @@ -50,7 +50,7 @@ manpage_intro: | By default, `jq` reads a stream of JSON objects (whitespace separated) from `stdin`. One or more may be specified, in which case `jq` will read input from those instead. - + The are described in the [INVOKING JQ] section, they mostly concern input and output formatting. The is written in the jq language and specifies how to transform the input @@ -68,11 +68,11 @@ manpage_epilogue: | ## AUTHOR Stephen Dolan `` - + sections: - title: Invoking jq body: | - + jq filters run on a stream of 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. The @@ -83,46 +83,46 @@ sections: using some command-line options: * `--slurp`/`-s`: - + Instead of running the filter for each JSON object in the input, read the entire input stream into a large array and run the filter just once. - + * `--raw-input`/`-R`: - + Don't parse the input as JSON. Instead, each line of text is passed to the filter as a string. If combined with `--slurp`, then the entire input is passed to the filter as a single long string. - + * `--null-input`/`-n`: - + Don't read any input at all! Instead, the filter is run once using `null` as the input. This is useful when using jq as a simple calculator or to construct JSON data from scratch. - + * `--compact-output` / `-c`: - + By default, jq pretty-prints JSON output. Using this option will result in more compact output by instead putting each JSON object on a single line. - + * `--colour-output` / `-C` and `--monochrome-output` / `-M`: - + By default, jq outputs colored JSON if writing to a terminal. You can force it to produce color even if writing to a pipe or a file using `-C`, and disable color with `-M`. - + * `--ascii-output` / `-a`: - + jq usually outputs non-ASCII Unicode codepoints as UTF-8, even if the input specified them as escape sequences (like "\u03bc"). Using this option, you can force jq to produce pure ASCII output with every non-ASCII character replaced with the equivalent escape sequence. - + * `--raw-output` / `-r`: - + With this option, if the filter's result is a string then it will be written directly to standard output rather than being formatted as a JSON string with quotes. This can be useful for @@ -138,7 +138,7 @@ sections: entries: - title: "`.`" body: | - + The absolute simplest (and least interesting) filter is `.`. This is a filter that takes its input and produces it unchanged as output. @@ -154,7 +154,7 @@ sections: - title: "`.foo`" body: | - + The simplest *useful* filter is .foo. When given a JSON object (aka dictionary or hash) as input, it produces the value at the key "foo", or null if there's none present. @@ -169,7 +169,7 @@ sections: - title: "`.[foo]`, `.[2]`, `.[10:15]`" body: | - + You can also look up fields of an object using syntax like `.["foo"]` (.foo above is a shorthand version of this). This one works for arrays as well, if the key is an @@ -195,7 +195,7 @@ sections: - program: '.[2:4]' input: '["a","b","c","d","e"]' output: ['["c", "d"]'] - + - program: '.[:3]' input: '["a","b","c","d","e"]' output: ['["a", "b", "c"]'] @@ -206,7 +206,7 @@ sections: - title: "`.[]`" body: | - + If you use the `.[foo]` syntax, but omit the index entirely, it will return *all* of the elements of an array. Running `.[]` with the input `[1,2,3]` will produce the @@ -233,7 +233,7 @@ sections: - title: "`,`" body: | - + If two filters are separated by a comma, then the input will be fed into both and there will be multiple outputs: first, all of the outputs produced by the left @@ -248,18 +248,18 @@ sections: - program: ".user, .projects[]" input: '{"user":"stedolan", "projects": ["jq", "wikiflow"]}' - output: ['"stedolan"', '"jq"', '"wikiflow"'] - + output: ['"stedolan"', '"jq"', '"wikiflow"'] + - program: '.[4,2]' input: '["a","b","c","d","e"]' output: ['"e"', '"c"'] - + - title: "`|`" body: | The | operator combines two filters by feeding the output(s) of the one on the left into the input of the one on the right. It's pretty much the same as the Unix shell's pipe, if you're used to - that. + that. If the one on the left produces multiple results, the one on the right will be run for each of those results. So, the @@ -273,7 +273,7 @@ sections: - title: Types and Values body: | - + jq supports the same set of datatypes as JSON - numbers, strings, booleans, arrays, objects (which in JSON-speak are hashes with only string keys), and "null". @@ -287,7 +287,7 @@ sections: entries: - title: Array construction - `[]` body: | - + As in JSON, `[]` is used to construct arrays, as in `[1,2,3]`. The elements of the arrays can be any jq expression. All of the results produced by all of the @@ -295,7 +295,7 @@ sections: to construct an array out of a known quantity of values (as in `[.foo, .bar, .baz]`) or to "collect" all the results of a filter into an array (as in `[.items[].name]`) - + Once you understand the "," operator, you can look at jq's array syntax in a different light: the expression `[1,2,3]` is not using a built-in syntax for comma-separated arrays, but is instead applying @@ -315,49 +315,49 @@ sections: Like JSON, `{}` is for constructing objects (aka dictionaries or hashes), as in: `{"a": 42, "b": 17}`. - + If the keys are "sensible" (all alphabetic characters), then the quotes can be left off. The value can be any expression (although you may need to wrap it in parentheses if it's a complicated one), which gets applied to the {} expression's input (remember, all filters have an input and an output). - + {foo: .bar} - + will produce the JSON object `{"foo": 42}` if given the JSON object `{"bar":42, "baz":43}`. You can use this to select particular fields of an object: if the input is an object with "user", "title", "id", and "content" fields and you just want "user" and "title", you can write - + {user: .user, title: .title} - + Because that's so common, there's a shortcut syntax: `{user, title}`. - + If one of the expressions produces multiple results, multiple dictionaries will be produced. If the input's - + {"user":"stedolan","titles":["JQ Primer", "More JQ"]} - + then the expression - + {user, title: .titles[]} - - will produce two outputs: - + + will produce two outputs: + {"user":"stedolan", "title": "JQ Primer"} {"user":"stedolan", "title": "More JQ"} - + Putting parentheses around the key means it will be evaluated as an expression. With the same input as above, - + {(.user): .titles} - + produces - + {"stedolan": ["JQ Primer", "More JQ"]} - + examples: - program: '{user, title: .titles[]}' input: '{"user":"stedolan","titles":["JQ Primer", "More JQ"]}' @@ -376,7 +376,7 @@ sections: etc.). However, jq never does implicit type conversions. If you try to add a string to an object you'll get an error message and no result. - + entries: - title: Addition - `+` body: | @@ -390,12 +390,12 @@ sections: - **Arrays** are added by being concatenated into a larger array. - **Strings** are added by being joined into a larger string. - + - **Objects** are added by merging, that is, inserting all the key-value pairs from both objects into a single combined object. If both objects contain a value for the same key, the object on the right of the `+` wins. - + `null` can be added to any value, and returns the other value unchanged. @@ -464,7 +464,7 @@ sections: - title: `keys` body: | - + The builtin function `keys`, when given an object, returns its keys in an array. @@ -487,7 +487,7 @@ sections: - title: `has` body: | - + The builtin function `has` returns whether the input object has the given key, or the input array has an element at the given index. @@ -506,11 +506,11 @@ sections: - title: `to_entries`, `from_entries`, `with_entries` body: | - + These functions convert between an object and an array of key-value pairs. If `to_entries` is passed an object, then for each `k: v` entry in the input, the output array - includes `{"key": k, "value": v}`. + includes `{"key": k, "value": v}`. `from_entries` does the opposite conversion, and `with_entries(foo)` is a shorthand for `to_entries | @@ -531,7 +531,7 @@ sections: - title: `select` body: | - + The function `select(foo)` produces its input unchanged if `foo` returns true for that input, and produces no output otherwise. @@ -546,7 +546,7 @@ sections: - title: `empty` body: | - + `empty` returns no results. None at all. Not even `null`. It's useful on occasion. You'll know if you need it :) @@ -598,10 +598,10 @@ sections: - title: `range` body: | - + The `range` function produces a range of numbers. `range(4;10)` produces 6 numbers, from 4 (inclusive) to 10 (exclusive). The numbers - are produced as separate outputs. Use `[range(4;10)]` to get a range as + are produced as separate outputs. Use `[range(4;10)]` to get a range as an array. examples: @@ -611,7 +611,7 @@ sections: - program: '[range(2;4)]' input: 'null' output: ['[2,3]'] - + - title: `tonumber` body: | @@ -638,7 +638,7 @@ sections: - title: `type` body: | - + The `type` function returns the type of its argument as a string, which is one of null, boolean, number, string, array or object. @@ -650,7 +650,7 @@ sections: - title: `sort, sort_by` body: | - + The `sort` functions sorts its input, which must be an array. Values are sorted in the following order: @@ -682,7 +682,7 @@ sections: - title: `group_by` body: | - + `group_by(.foo)` takes as input an array, groups the elements having the same `.foo` field into separate arrays, and produces all of these arrays as elements of a larger @@ -699,7 +699,7 @@ sections: - title: `min`, `max`, `min_by`, `max_by` body: | - + Find the minimum or maximum element of the input array. The `_by` versions allow you to specify a particular field or property to examine, e.g. `min_by(.foo)` finds the object @@ -715,7 +715,7 @@ sections: - title: `unique` body: | - + The `unique` function takes as input an array and produces an array of the same elements, in sorted order, with duplicates removed. @@ -727,7 +727,7 @@ sections: - title: `reverse` body: | - + This function reverses an array. examples: @@ -766,7 +766,7 @@ sections: - title: `recurse` body: | - + The `recurse` function allows you to search through a recursive structure, and extract interesting data from all levels. Suppose your input represents a filesystem: @@ -778,7 +778,7 @@ sections: {"name": "/home", "children": [ {"name": "/home/stephen", "children": [ {"name": "/home/stephen/jq", "children": []}]}]}]} - + Now suppose you want to extract all of the filenames present. You need to retrieve `.name`, `.children[].name`, `.children[].children[].name`, and so on. You can do this @@ -789,7 +789,7 @@ sections: examples: - program: 'recurse(.foo[])' input: '{"foo":[{"foo": []}, {"foo":[{"foo":[]}]}]}' - output: + output: - '{"foo":[{"foo":[]},{"foo":[{"foo":[]}]}]}' - '{"foo":[]}' - '{"foo":[{"foo":[]}]}' @@ -807,7 +807,7 @@ sections: - program: '"The input was \(.), which is one less than \(.+1)"' input: '42' output: ['"The input was 42, which is one less than 43"'] - + - title: "Format strings and escaping" body: | @@ -836,17 +836,17 @@ sections: characters to a `%xx` sequence. * `@csv`: - + The input must be an array, and it is rendered as CSV with double quotes for strings, and quotes escaped by repetition. * `@sh`: - + The input is escaped suitable for use in a command-line for a POSIX shell. If the input is an array, the output will be a series of space-separated strings. - + * `@base64`: The input is converted to base64 as specified by RFC 4648. @@ -879,7 +879,7 @@ sections: - program: '@sh "echo \(.)"' input: "\"O'Hara's Ale\"" output: ["\"echo 'O'\\\\''Hara'\\\\''s Ale'\""] - + - title: Conditionals and Comparisons entries: - title: `==`, `!=` @@ -891,7 +891,7 @@ sections: to numbers. If you're coming from Javascript, jq's == is like Javascript's === - considering values equal only when they have the same type as well as the same value. - + != is "not equal", and 'a != b' returns the opposite value of 'a == b' examples: @@ -904,7 +904,7 @@ sections: `if A then B else C end` will act the same as `B` if `A` produces a value other than false or null, but act the same as `C` otherwise. - + Checking for false or null is a simpler notion of "truthiness" than is found in Javascript or Python, but it means that you'll sometimes have to be more explicit about @@ -912,11 +912,11 @@ sections: string is empty using `if .name then A else B end`, you'll need something more like `if (.name | count) > 0 then A else B end` instead. - + If the condition A produces multiple results, it is considered "true" if any of those results is not false or null. If it produces zero results, it's considered false. - + More cases can be added to an if using `elif A then B` syntax. examples: @@ -930,10 +930,10 @@ sections: end input: 2 output: ['"many"'] - + - title: `>, >=, <=, <` body: | - + The comparison operators `>`, `>=`, `<=`, `<` return whether their left argument is greater than, greater than or equal to, less than or equal to or less than their right argument @@ -960,14 +960,14 @@ sections: so it is called as a filter to which things can be piped rather than with special syntax, as in `.foo and .bar | not`. - + These three only produce the values "true" and "false", and so are only useful for genuine Boolean operations, rather than the common Perl/Python/Ruby idiom of "value_that_may_be_null or default". If you want to use this form of "or", picking between two values rather than evaluating a condition, see the "//" operator below. - + examples: - program: '42 and "a string"' input: 'null' @@ -1005,7 +1005,7 @@ sections: - program: '.foo // 42' input: '{}' output: [42] - + - title: Advanced features body: | Variables are an absolute necessity in most programming languages, but @@ -1030,67 +1030,67 @@ sections: entries: - title: Variables body: | - + In jq, all filters have an input and an output, so manual plumbing is not necessary to pass a value from one part of a program to the next. Many expressions, for instance `a + b`, pass their input to two distinct subexpressions (here `a` and `b` are both passed the same input), so variables aren't usually necessary in order to use a value twice. - + For instance, calculating the average value of an array of numbers requires a few variables in most languages - at least one to hold the array, perhaps one for each element or for a loop counter. In jq, it's simply `add / length` - the `add` expression is given the array and produces its sum, and the `length` expression is given the array and produces its length. - + So, there's generally a cleaner way to solve most problems in jq that defining variables. Still, sometimes they do make things easier, so jq lets you define variables using `expression as $variable`. All variable names start with `$`. Here's a slightly uglier version of the array-averaging example: - + length as $array_length | add / $array_length - + We'll need a more complicated problem to find a situation where using variables actually makes our lives easier. - - + + Suppose we have an array of blog posts, with "author" and "title" fields, and another object which is used to map author usernames to real names. Our input looks like: - + {"posts": [{"title": "Frist psot", "author": "anon"}, {"title": "A well-written article", "author": "person1"}], "realnames": {"anon": "Anonymous Coward", "person1": "Person McPherson"}} - + We want to produce the posts with the author field containing a real name, as in: - + {"title": "Frist psot", "author": "Anonymous Coward"} {"title": "A well-written article", "author": "Person McPherson"} - + We use a variable, $names, to store the realnames object, so that we can refer to it later when looking up author usernames: - + .realnames as $names | .posts[] | {title, author: $names[.author]} - + The expression `exp as $x | ...` means: for each value of expression `exp`, run the rest of the pipeline with the entire original input, and - with `$x` set to that value. Thus `as` functions as something of a + with `$x` set to that value. Thus `as` functions as something of a foreach loop. Variables are scoped over the rest of the expression that defines - them, so - + them, so + .realnames as $names | (.posts[] | {title, author: $names[.author]}) - - will work, but - + + will work, but + (.realnames as $names | .posts[]) | {title, author: $names[.author]} - + won't. examples: @@ -1100,11 +1100,11 @@ sections: - title: 'Defining Functions' body: | - + You can give a filter a name using "def" syntax: def increment: . + 1; - + From then on, `increment` is usable as a filter just like a builtin function (in fact, this is how some of the builtins are defined). A function may take arguments: @@ -1135,19 +1135,19 @@ sections: - title: Reduce body: | - + The `reduce` syntax in jq allows you to combine all of the results of an expression by accumulating them into a single answer. As an example, we'll pass `[3,2,1]` to this expression: reduce .[] as $item (0; . + $item) - + For each result that `.[]` produces, `. + $item` is run to accumulate a running total, starting from 0. In this example, `.[]` produces the results 3, 2, and 1, so the effect is similar to running something like this: - 0 | (3 as $item | . + $item) | + 0 | (3 as $item | . + $item) | (2 as $item | . + $item) | (1 as $item | . + $item) @@ -1155,7 +1155,7 @@ sections: - program: 'reduce .[] as $item (0; . + $item)' input: '[10,2,5,3]' output: ['20'] - + - title: Assignment body: | @@ -1177,14 +1177,14 @@ sections: entries: - title: "`=`" body: | - + The filter `.foo = 1` will take as input an object and produce as output an object with the "foo" field set to 1. There is no notion of "modifying" or "changing" something in jq - all jq values are immutable. For instance, - + .foo = .bar | .foo.baz = 1 - + will not have the side-effect of setting .bar.baz to be set to 1, as the similar-looking program in Javascript, Python, Ruby or other languages would. Unlike these languages (but @@ -1193,7 +1193,7 @@ sections: "the same object". They can be equal, or not equal, but if we change one of them in no circumstances will the other change behind our backs. - + This means that it's impossible to build circular values in jq (such as an array whose first element is itself). This is quite intentional, and ensures that anything a jq program @@ -1206,14 +1206,14 @@ sections: works out the new value for the property being assigned to by running the old value through this expression. For instance, .foo |= .+1 will build an object with the "foo" field set to the input's "foo" plus 1. - + This example should show the difference between '=' and '|=': - + Provide input '{"a": {"b": 10}, "b": 20}' to the programs: - + .a = .b .a |= .b - + The former will set the "a" field of the input to the "b" field of the input, and produce the output {"a": 20}. The latter will set the "a" field of the input to the "a" field's "b" field, producing {"a": 10}. @@ -1228,43 +1228,43 @@ sections: - program: .foo += 1 input: '{"foo": 42}' output: ['{"foo": 43}'] - + - title: Complex assignments body: | Lots more things are allowed on the left-hand side of a jq assignment than in most langauges. We've already seen simple field accesses on the left hand side, and it's no surprise that array accesses work just as well: - + .posts[0].title = "JQ Manual" - + What may come as a surprise is that the expression on the left may produce multiple results, referring to different points in the input document: - + .posts[].comments |= . + ["this is great"] - + That example appends the string "this is great" to the "comments" array of each post in the input (where the input is an object with a field "posts" which is an array of posts). - + When jq encounters an assignment like 'a = b', it records the "path" taken to select a part of the input document while executing a. This path is then used to find which part of the input to change while executing the assignment. Any filter may be used on the left-hand side of an equals - whichever paths it selects from the input will be where the assignment is performed. - + This is a very powerful operation. Suppose we wanted to add a comment to blog posts, using the same "blog" input above. This time, we only want to comment on the posts written by "stedolan". We can find those posts using the "select" function described earlier: - + .posts[] | select(.author == "stedolan") - + The paths provided by this operation point to each of the posts that "stedolan" wrote, and we can comment on each of them in the same way that we did before: - + (.posts[] | select(.author == "stedolan") | .comments) |= . + ["terrible."] diff --git a/docs/content/3.manual/v1.4/manual.yml b/docs/content/3.manual/v1.4/manual.yml index 3933b4d..482e781 100644 --- a/docs/content/3.manual/v1.4/manual.yml +++ b/docs/content/3.manual/v1.4/manual.yml @@ -16,7 +16,7 @@ body: | 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. Piping that filter into a second runs the second filter for each element of the @@ -50,7 +50,7 @@ manpage_intro: | By default, `jq` reads a stream of JSON objects (whitespace separated) from `stdin`. One or more may be specified, in which case `jq` will read input from those instead. - + The are described in the [INVOKING JQ] section, they mostly concern input and output formatting. The is written in the jq language and specifies how to transform the input @@ -68,11 +68,11 @@ manpage_epilogue: | ## AUTHOR Stephen Dolan `` - + sections: - title: Invoking jq body: | - + jq filters run on a stream of 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. The @@ -98,44 +98,44 @@ sections: Output the jq version and exit with zero. * `--slurp`/`-s`: - + Instead of running the filter for each JSON object in the input, read the entire input stream into a large array and run the filter just once. * `--online-input`/`-I`: - + When the top-level input value is an array produce its elements instead of the array. This allows on-line processing of potentially very large top-level arrays' elements. - + * `--raw-input`/`-R`: - + Don't parse the input as JSON. Instead, each line of text is passed to the filter as a string. If combined with `--slurp`, then the entire input is passed to the filter as a single long string. - + * `--null-input`/`-n`: - + Don't read any input at all! Instead, the filter is run once using `null` as the input. This is useful when using jq as a simple calculator or to construct JSON data from scratch. - + * `--compact-output` / `-c`: - + By default, jq pretty-prints JSON output. Using this option will result in more compact output by instead putting each JSON object on a single line. - + * `--colour-output` / `-C` and `--monochrome-output` / `-M`: - + By default, jq outputs colored JSON if writing to a terminal. You can force it to produce color even if writing to a pipe or a file using `-C`, and disable color with `-M`. - + * `--ascii-output` / `-a`: - + jq usually outputs non-ASCII Unicode codepoints as UTF-8, even if the input specified them as escape sequences (like "\u03bc"). Using this option, you can force jq to produce pure @@ -149,11 +149,11 @@ sections: output elsewhere). * `--sort-keys` / `-S`: - + Output the fields of each object with the keys in sorted order. * `--raw-output` / `-r`: - + With this option, if the filter's result is a string then it will be written directly to standard output rather than being formatted as a JSON string with quotes. This can be useful for @@ -191,7 +191,7 @@ sections: entries: - title: "`.`" body: | - + The absolute simplest (and least interesting) filter is `.`. This is a filter that takes its input and produces it unchanged as output. @@ -207,7 +207,7 @@ sections: - title: "`.foo`, `.foo.bar`" body: | - + The simplest *useful* filter is `.foo`. When given a JSON object (aka dictionary or hash) as input, it produces the value at the key "foo", or null if there's none present. @@ -216,7 +216,7 @@ sections: it with double quotes like this: `."foo$"`. A filter of the form `.foo.bar` is equivalent to `.foo|.bar`. - + examples: - program: '.foo' input: '{"foo": 42, "bar": "less interesting data"}' @@ -230,7 +230,7 @@ sections: - title: "`.foo?`" body: | - + Just like `.foo`, but does not output even an error when `.` is not an array or an object. @@ -250,7 +250,7 @@ sections: - title: "`.[]`, `.[2]`, `.[10:15]`" body: | - + You can also look up fields of an object using syntax like `.["foo"]` (.foo above is a shorthand version of this). This one works for arrays as well, if the key is an @@ -285,7 +285,7 @@ sections: - program: '.[2:4]' input: '"abcdefghi"' output: ['"cd"'] - + - program: '.[:3]' input: '["a","b","c","d","e"]' output: ['["a", "b", "c"]'] @@ -296,7 +296,7 @@ sections: - title: "`.[]`" body: | - + If you use the `.[index]` syntax, but omit the index entirely, it will return *all* of the elements of an array. Running `.[]` with the input `[1,2,3]` will produce the @@ -323,13 +323,13 @@ sections: - title: "`.[]?`" body: | - + Like `.[]`, but no errors will be output if . is not an array or object. - title: "`,`" body: | - + If two filters are separated by a comma, then the input will be fed into both and there will be multiple outputs: first, all of the outputs produced by the left @@ -344,18 +344,18 @@ sections: - program: ".user, .projects[]" input: '{"user":"stedolan", "projects": ["jq", "wikiflow"]}' - output: ['"stedolan"', '"jq"', '"wikiflow"'] - + output: ['"stedolan"', '"jq"', '"wikiflow"'] + - program: '.[4,2]' input: '["a","b","c","d","e"]' output: ['"e"', '"c"'] - + - title: "`|`" body: | The | operator combines two filters by feeding the output(s) of the one on the left into the input of the one on the right. It's pretty much the same as the Unix shell's pipe, if you're used to - that. + that. If the one on the left produces multiple results, the one on the right will be run for each of those results. So, the @@ -369,7 +369,7 @@ sections: - title: Types and Values body: | - + jq supports the same set of datatypes as JSON - numbers, strings, booleans, arrays, objects (which in JSON-speak are hashes with only string keys), and "null". @@ -383,7 +383,7 @@ sections: entries: - title: Array construction - `[]` body: | - + As in JSON, `[]` is used to construct arrays, as in `[1,2,3]`. The elements of the arrays can be any jq expression. All of the results produced by all of the @@ -391,7 +391,7 @@ sections: to construct an array out of a known quantity of values (as in `[.foo, .bar, .baz]`) or to "collect" all the results of a filter into an array (as in `[.items[].name]`) - + Once you understand the "," operator, you can look at jq's array syntax in a different light: the expression `[1,2,3]` is not using a built-in syntax for comma-separated arrays, but is instead applying @@ -411,49 +411,49 @@ sections: Like JSON, `{}` is for constructing objects (aka dictionaries or hashes), as in: `{"a": 42, "b": 17}`. - + If the keys are "sensible" (all alphabetic characters), then the quotes can be left off. The value can be any expression (although you may need to wrap it in parentheses if it's a complicated one), which gets applied to the {} expression's input (remember, all filters have an input and an output). - + {foo: .bar} - + will produce the JSON object `{"foo": 42}` if given the JSON object `{"bar":42, "baz":43}`. You can use this to select particular fields of an object: if the input is an object with "user", "title", "id", and "content" fields and you just want "user" and "title", you can write - + {user: .user, title: .title} - + Because that's so common, there's a shortcut syntax: `{user, title}`. - + If one of the expressions produces multiple results, multiple dictionaries will be produced. If the input's - + {"user":"stedolan","titles":["JQ Primer", "More JQ"]} - + then the expression - + {user, title: .titles[]} - - will produce two outputs: - + + will produce two outputs: + {"user":"stedolan", "title": "JQ Primer"} {"user":"stedolan", "title": "More JQ"} - + Putting parentheses around the key means it will be evaluated as an expression. With the same input as above, - + {(.user): .titles} - + produces - + {"stedolan": ["JQ Primer", "More JQ"]} - + examples: - program: '{user, title: .titles[]}' input: '{"user":"stedolan","titles":["JQ Primer", "More JQ"]}' @@ -472,7 +472,7 @@ sections: etc.). However, jq never does implicit type conversions. If you try to add a string to an object you'll get an error message and no result. - + entries: - title: Addition - `+` body: | @@ -486,13 +486,13 @@ sections: - **Arrays** are added by being concatenated into a larger array. - **Strings** are added by being joined into a larger string. - + - **Objects** are added by merging, that is, inserting all the key-value pairs from both objects into a single combined object. If both objects contain a value for the same key, the object on the right of the `+` wins. (For recursive merge use the `*` operator.) - + `null` can be added to any value, and returns the other value unchanged. @@ -578,7 +578,7 @@ sections: - title: "`keys`" body: | - + The builtin function `keys`, when given an object, returns its keys in an array. @@ -601,7 +601,7 @@ sections: - title: "`has`" body: | - + The builtin function `has` returns whether the input object has the given key, or the input array has an element at the given index. @@ -620,10 +620,10 @@ sections: - title: "`del`" body: | - + The builtin function `del` removes a key and its corresponding value from an object. - + examples: - program: 'del(.foo)' input: '[{"foo": 42, "bar": 9001, "baz": 42}]' @@ -634,11 +634,11 @@ sections: - title: "`to_entries`, `from_entries`, `with_entries`" body: | - + These functions convert between an object and an array of key-value pairs. If `to_entries` is passed an object, then for each `k: v` entry in the input, the output array - includes `{"key": k, "value": v}`. + includes `{"key": k, "value": v}`. `from_entries` does the opposite conversion, and `with_entries(foo)` is a shorthand for `to_entries | @@ -659,7 +659,7 @@ sections: - title: "`select`" body: | - + The function `select(foo)` produces its input unchanged if `foo` returns true for that input, and produces no output otherwise. @@ -675,7 +675,7 @@ sections: - title: "`arrays`, `objects`, `iterables`, `booleans`, `numbers`, `strings`, `nulls`, `values`, `scalars`" body: | - + These built-ins select only inputs that are arrays, objects, iterables (arrays or objects), booleans, numbers, strings, null, non-null values, and non-iterables, respectively. @@ -687,7 +687,7 @@ sections: - title: "`empty`" body: | - + `empty` returns no results. None at all. Not even `null`. It's useful on occasion. You'll know if you need it :) @@ -721,7 +721,7 @@ sections: Outputs the paths to all the elements in its input (except it does not output the empty list, representing . itself). - `paths` is equivalent to + `paths` is equivalent to def paths: path(recurse(if (type|. == "array" or . == "object") then .[] else empty end))|select(length > 0); @@ -765,13 +765,13 @@ sections: - title: "`any`" body: | - + The filter `any` takes as input an array of boolean values, and produces `true` as output if any of the the elements of the array is `true`. - + If the input is an empty array, `any` returns `false`. - + examples: - program: any input: '[true, false]' @@ -785,13 +785,13 @@ sections: - title: "`all`" body: | - + The filter `all` takes as input an array of boolean values, and produces `true` as output if all of the the elements of the array are `true`. - + If the input is an empty array, `all` returns `true`. - + examples: - program: all input: '[true, false]' @@ -805,10 +805,10 @@ sections: - title: "`range`" body: | - + The `range` function produces a range of numbers. `range(4;10)` produces 6 numbers, from 4 (inclusive) to 10 (exclusive). The numbers - are produced as separate outputs. Use `[range(4;10)]` to get a range as + are produced as separate outputs. Use `[range(4;10)]` to get a range as an array. examples: @@ -818,7 +818,7 @@ sections: - program: '[range(2;4)]' input: 'null' output: ['[2,3]'] - + - title: "`floor`" body: | @@ -828,7 +828,7 @@ sections: - program: 'floor' input: '3.14159' output: ['3'] - + - title: "`sqrt`" body: | @@ -838,7 +838,7 @@ sections: - program: 'sqrt' input: '9' output: ['3'] - + - title: "`tonumber`" body: | @@ -865,7 +865,7 @@ sections: - title: "`type`" body: | - + The `type` function returns the type of its argument as a string, which is one of null, boolean, number, string, array or object. @@ -877,7 +877,7 @@ sections: - title: "`sort, sort_by`" body: | - + The `sort` functions sorts its input, which must be an array. Values are sorted in the following order: @@ -909,7 +909,7 @@ sections: - title: "`group_by`" body: | - + `group_by(.foo)` takes as input an array, groups the elements having the same `.foo` field into separate arrays, and produces all of these arrays as elements of a larger @@ -926,7 +926,7 @@ sections: - title: "`min`, `max`, `min_by`, `max_by`" body: | - + Find the minimum or maximum element of the input array. The `_by` versions allow you to specify a particular field or property to examine, e.g. `min_by(.foo)` finds the object @@ -942,7 +942,7 @@ sections: - title: "`unique`" body: | - + The `unique` function takes as input an array and produces an array of the same elements, in sorted order, with duplicates removed. @@ -954,13 +954,13 @@ sections: - title: "`unique_by`" body: | - + The `unique_by(.foo)` function takes as input an array and produces an array of the same elements, in sorted order, with elqements with a duplicate `.foo` field removed. Think of it as making an array by taking one element out of every group produced by `group_by`. - + examples: - program: 'unique_by(.foo)' input: '[{"foo": 1, "bar": 2}, {"foo": 1, "bar": 3}, {"foo": 4, "bar": 5}]' @@ -972,7 +972,7 @@ sections: - title: "`reverse`" body: | - + This function reverses an array. examples: @@ -1117,12 +1117,12 @@ sections: - title: "`join`" body: | - + Joins the array of elements given as input, using the argument as separator. It is the inverse of `split`: that is, running `split("foo") | join("foo")` over any input string returns said input string. - + examples: - program: 'join(", ")' input: '["a","b,c,d","e"]' @@ -1131,7 +1131,7 @@ sections: - title: "`recurse`" body: | - + The `recurse` function allows you to search through a recursive structure, and extract interesting data from all levels. Suppose your input represents a filesystem: @@ -1143,7 +1143,7 @@ sections: {"name": "/home", "children": [ {"name": "/home/stephen", "children": [ {"name": "/home/stephen/jq", "children": []}]}]}]} - + Now suppose you want to extract all of the filenames present. You need to retrieve `.name`, `.children[].name`, `.children[].children[].name`, and so on. You can do this @@ -1154,7 +1154,7 @@ sections: examples: - program: 'recurse(.foo[])' input: '{"foo":[{"foo": []}, {"foo":[{"foo":[]}]}]}' - output: + output: - '{"foo":[{"foo":[]},{"foo":[{"foo":[]}]}]}' - '{"foo":[]}' - '{"foo":[{"foo":[]}]}' @@ -1162,14 +1162,14 @@ sections: - title: "`recurse_down`" body: | - + A quieter version of `recurse(.[])`, equivalent to: def recurse_down: recurse(.[]?); - title: "`..`" body: | - + Short-hand for `recurse_down`. This is intended to resemble the XPath `//` operator. Note that `..a` does not work; use `..|a` instead. @@ -1190,7 +1190,7 @@ sections: - program: '"The input was \(.), which is one less than \(.+1)"' input: '42' output: ['"The input was 42, which is one less than 43"'] - + - title: "Convert to/from JSON" body: | @@ -1238,17 +1238,17 @@ sections: characters to a `%xx` sequence. * `@csv`: - + The input must be an array, and it is rendered as CSV with double quotes for strings, and quotes escaped by repetition. * `@sh`: - + The input is escaped suitable for use in a command-line for a POSIX shell. If the input is an array, the output will be a series of space-separated strings. - + * `@base64`: The input is converted to base64 as specified by RFC 4648. @@ -1281,7 +1281,7 @@ sections: - program: '@sh "echo \(.)"' input: "\"O'Hara's Ale\"" output: ["\"echo 'O'\\\\''Hara'\\\\''s Ale'\""] - + - title: Conditionals and Comparisons entries: - title: "`==`, `!=`" @@ -1293,7 +1293,7 @@ sections: to numbers. If you're coming from Javascript, jq's == is like Javascript's === - considering values equal only when they have the same type as well as the same value. - + != is "not equal", and 'a != b' returns the opposite value of 'a == b' examples: @@ -1306,7 +1306,7 @@ sections: `if A then B else C end` will act the same as `B` if `A` produces a value other than false or null, but act the same as `C` otherwise. - + Checking for false or null is a simpler notion of "truthiness" than is found in Javascript or Python, but it means that you'll sometimes have to be more explicit about @@ -1314,11 +1314,11 @@ sections: string is empty using `if .name then A else B end`, you'll need something more like `if (.name | length) > 0 then A else B end` instead. - + If the condition A produces multiple results, it is considered "true" if any of those results is not false or null. If it produces zero results, it's considered false. - + More cases can be added to an if using `elif A then B` syntax. examples: @@ -1332,10 +1332,10 @@ sections: end input: 2 output: ['"many"'] - + - title: "`>, >=, <=, <`" body: | - + The comparison operators `>`, `>=`, `<=`, `<` return whether their left argument is greater than, greater than or equal to, less than or equal to or less than their right argument @@ -1362,14 +1362,14 @@ sections: so it is called as a filter to which things can be piped rather than with special syntax, as in `.foo and .bar | not`. - + These three only produce the values "true" and "false", and so are only useful for genuine Boolean operations, rather than the common Perl/Python/Ruby idiom of "value_that_may_be_null or default". If you want to use this form of "or", picking between two values rather than evaluating a condition, see the "//" operator below. - + examples: - program: '42 and "a string"' input: 'null' @@ -1407,7 +1407,7 @@ sections: - program: '.foo // 42' input: '{}' output: [42] - + - title: Advanced features body: | Variables are an absolute necessity in most programming languages, but @@ -1432,67 +1432,67 @@ sections: entries: - title: Variables body: | - + In jq, all filters have an input and an output, so manual plumbing is not necessary to pass a value from one part of a program to the next. Many expressions, for instance `a + b`, pass their input to two distinct subexpressions (here `a` and `b` are both passed the same input), so variables aren't usually necessary in order to use a value twice. - + For instance, calculating the average value of an array of numbers requires a few variables in most languages - at least one to hold the array, perhaps one for each element or for a loop counter. In jq, it's simply `add / length` - the `add` expression is given the array and produces its sum, and the `length` expression is given the array and produces its length. - + So, there's generally a cleaner way to solve most problems in jq than defining variables. Still, sometimes they do make things easier, so jq lets you define variables using `expression as $variable`. All variable names start with `$`. Here's a slightly uglier version of the array-averaging example: - + length as $array_length | add / $array_length - + We'll need a more complicated problem to find a situation where using variables actually makes our lives easier. - - + + Suppose we have an array of blog posts, with "author" and "title" fields, and another object which is used to map author usernames to real names. Our input looks like: - + {"posts": [{"title": "Frist psot", "author": "anon"}, {"title": "A well-written article", "author": "person1"}], "realnames": {"anon": "Anonymous Coward", "person1": "Person McPherson"}} - + We want to produce the posts with the author field containing a real name, as in: - + {"title": "Frist psot", "author": "Anonymous Coward"} {"title": "A well-written article", "author": "Person McPherson"} - + We use a variable, $names, to store the realnames object, so that we can refer to it later when looking up author usernames: - + .realnames as $names | .posts[] | {title, author: $names[.author]} - + The expression `exp as $x | ...` means: for each value of expression `exp`, run the rest of the pipeline with the entire original input, and - with `$x` set to that value. Thus `as` functions as something of a + with `$x` set to that value. Thus `as` functions as something of a foreach loop. Variables are scoped over the rest of the expression that defines - them, so - + them, so + .realnames as $names | (.posts[] | {title, author: $names[.author]}) - - will work, but - + + will work, but + (.realnames as $names | .posts[]) | {title, author: $names[.author]} - + won't. examples: @@ -1502,11 +1502,11 @@ sections: - title: 'Defining Functions' body: | - + You can give a filter a name using "def" syntax: def increment: . + 1; - + From then on, `increment` is usable as a filter just like a builtin function (in fact, this is how some of the builtins are defined). A function may take arguments: @@ -1537,19 +1537,19 @@ sections: - title: Reduce body: | - + The `reduce` syntax in jq allows you to combine all of the results of an expression by accumulating them into a single answer. As an example, we'll pass `[3,2,1]` to this expression: reduce .[] as $item (0; . + $item) - + For each result that `.[]` produces, `. + $item` is run to accumulate a running total, starting from 0. In this example, `.[]` produces the results 3, 2, and 1, so the effect is similar to running something like this: - 0 | (3 as $item | . + $item) | + 0 | (3 as $item | . + $item) | (2 as $item | . + $item) | (1 as $item | . + $item) @@ -1557,7 +1557,7 @@ sections: - program: 'reduce .[] as $item (0; . + $item)' input: '[10,2,5,3]' output: ['20'] - + - title: Assignment body: | @@ -1579,14 +1579,14 @@ sections: entries: - title: "`=`" body: | - + The filter `.foo = 1` will take as input an object and produce as output an object with the "foo" field set to 1. There is no notion of "modifying" or "changing" something in jq - all jq values are immutable. For instance, - + .foo = .bar | .foo.baz = 1 - + will not have the side-effect of setting .bar.baz to be set to 1, as the similar-looking program in Javascript, Python, Ruby or other languages would. Unlike these languages (but @@ -1595,7 +1595,7 @@ sections: "the same object". They can be equal, or not equal, but if we change one of them in no circumstances will the other change behind our backs. - + This means that it's impossible to build circular values in jq (such as an array whose first element is itself). This is quite intentional, and ensures that anything a jq program @@ -1608,14 +1608,14 @@ sections: works out the new value for the property being assigned to by running the old value through this expression. For instance, .foo |= .+1 will build an object with the "foo" field set to the input's "foo" plus 1. - + This example should show the difference between '=' and '|=': - + Provide input '{"a": {"b": 10}, "b": 20}' to the programs: - + .a = .b .a |= .b - + The former will set the "a" field of the input to the "b" field of the input, and produce the output {"a": 20}. The latter will set the "a" field of the input to the "a" field's "b" field, producing {"a": 10}. @@ -1630,43 +1630,43 @@ sections: - program: .foo += 1 input: '{"foo": 42}' output: ['{"foo": 43}'] - + - title: Complex assignments body: | Lots more things are allowed on the left-hand side of a jq assignment than in most langauges. We've already seen simple field accesses on the left hand side, and it's no surprise that array accesses work just as well: - + .posts[0].title = "JQ Manual" - + What may come as a surprise is that the expression on the left may produce multiple results, referring to different points in the input document: - + .posts[].comments |= . + ["this is great"] - + That example appends the string "this is great" to the "comments" array of each post in the input (where the input is an object with a field "posts" which is an array of posts). - + When jq encounters an assignment like 'a = b', it records the "path" taken to select a part of the input document while executing a. This path is then used to find which part of the input to change while executing the assignment. Any filter may be used on the left-hand side of an equals - whichever paths it selects from the input will be where the assignment is performed. - + This is a very powerful operation. Suppose we wanted to add a comment to blog posts, using the same "blog" input above. This time, we only want to comment on the posts written by "stedolan". We can find those posts using the "select" function described earlier: - + .posts[] | select(.author == "stedolan") - + The paths provided by this operation point to each of the posts that "stedolan" wrote, and we can comment on each of them in the same way that we did before: - + (.posts[] | select(.author == "stedolan") | .comments) |= . + ["terrible."] diff --git a/docs/default_manpage.md b/docs/default_manpage.md index 878b836..b036cd7 100644 --- a/docs/default_manpage.md +++ b/docs/default_manpage.md @@ -4,13 +4,13 @@ jq(1) -- Command-line JSON processor ## DESCRIPTION `jq` can transform JSON in various ways, by selecting, iterating, -reducing and otherwise mangling JSON documents. +reducing and otherwise mangling JSON documents. This version of `jq` was built without a manual, so this manpage is a stub. For full documentation of the `jq` language, see: http://stedolan.github.io/jq - + ## BUGS Presumably. Report them or discuss them at: diff --git a/docs/public/.htaccess b/docs/public/.htaccess index 7142064..9e9f821 100644 --- a/docs/public/.htaccess +++ b/docs/public/.htaccess @@ -12,7 +12,7 @@ FileETag All -# Cache, aggressively +# Cache, aggressively ExpiresActive On ExpiresDefault "access plus 10 days" @@ -25,4 +25,4 @@ FileETag All # Mime-types AddType application/vnd.ms-fontobject .eot AddType font/ttf .ttf -AddType font/otf .otf \ No newline at end of file +AddType font/otf .otf diff --git a/docs/site.yml b/docs/site.yml index c3abfdc..d784cd4 100644 --- a/docs/site.yml +++ b/docs/site.yml @@ -8,7 +8,7 @@ jq_version: "1.4-2-g15c4a7f-dirty" root: '/jq' footer: | - + This website is made with [Bonsai](http://www.tinytree.info) and [Twitter Bootstrap](http://twitter.github.com/bootstrap/), themed with [Bootswatch](http://bootswatch.com). diff --git a/lexer.c b/lexer.c index 1ff4cba..c369898 100644 --- a/lexer.c +++ b/lexer.c @@ -1134,8 +1134,8 @@ YY_RULE_SETUP case 38: YY_RULE_SETUP #line 88 "lexer.l" -{ - yylval->literal = jv_parse_sized(yytext, yyleng); return LITERAL; +{ + yylval->literal = jv_parse_sized(yytext, yyleng); return LITERAL; } YY_BREAK case 39: @@ -2399,7 +2399,7 @@ static int try_exit(int c, int state, yyscan_t yyscanner) { case IN_BRACE: match = ret = '}'; break; case IN_QQINTERP: - match = ')'; + match = ')'; ret = QQSTRING_INTERP_END; break; diff --git a/lexer.l b/lexer.l index 8e46181..4f306b2 100644 --- a/lexer.l +++ b/lexer.l @@ -85,8 +85,8 @@ struct lexer_param; yylval->literal = jv_string_sized(yytext + 1, yyleng - 1); return FORMAT; } -[0-9.]+([eE][+-]?[0-9]+)? { - yylval->literal = jv_parse_sized(yytext, yyleng); return LITERAL; +[0-9.]+([eE][+-]?[0-9]+)? { + yylval->literal = jv_parse_sized(yytext, yyleng); return LITERAL; } "\"" { @@ -117,7 +117,7 @@ struct lexer_param; return INVALID_CHARACTER; } } - + ([a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]* { yylval->literal = jv_string(yytext); return IDENT;} \.[a-zA-Z_][a-zA-Z_0-9]* { yylval->literal = jv_string(yytext+1); return FIELD;} @@ -142,7 +142,7 @@ static int try_exit(int c, int state, yyscan_t yyscanner) { case IN_BRACE: match = ret = '}'; break; case IN_QQINTERP: - match = ')'; + match = ')'; ret = QQSTRING_INTERP_END; break; diff --git a/scripts/crosscompile b/scripts/crosscompile index 8d88bb2..127cbb5 100755 --- a/scripts/crosscompile +++ b/scripts/crosscompile @@ -1,6 +1,6 @@ #!/bin/sh -# This script is used to cross-compile binaries for +# This script is used to cross-compile binaries for # platforms other than the current one # Usage: $0 diff --git a/scripts/gen_utf8_tables.py b/scripts/gen_utf8_tables.py index 65d03a2..35cb66a 100644 --- a/scripts/gen_utf8_tables.py +++ b/scripts/gen_utf8_tables.py @@ -10,7 +10,7 @@ def print_table(type, name, t): first = True for i in range(0,len(t),16): print ((" {" if i == 0 else " ") + - ", ".join("0x%02x"%n for n in t[i:i+16]) + + ", ".join("0x%02x"%n for n in t[i:i+16]) + ("," if i + 16 < len(t) else "};")) @@ -22,7 +22,7 @@ def utf8info(c): if 0xE0 <= c <= 0xEF: return 3, mask(4) if 0xF0 <= c <= 0xF4: return 4, mask(3) if 0xF4 <= c <= 0xFF: return 0, 0 - + table = lambda i: [utf8info(c)[i] for c in range(256)] print("#define UTF8_CONTINUATION_BYTE ((unsigned char)255)")