Jq Concepts: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 34: Line 34:
The pipe operator '|' combines two filters by feeding the output of the filter specified on the left into the input of the filter specified on the right.
The pipe operator '|' combines two filters by feeding the output of the filter specified on the left into the input of the filter specified on the right.


If the left filter produces an [[#Iteration|iteration]]
If the left filter produces an [[#Iteration|iteration]], the filter on the right is applied to each of the iteration elements.
 
Usually the "|" can be omitted on command line and it can be implied:
 
<syntaxhighlight lang='java'>
jq '.a.b.c'
</syntaxhighlight>
 
is equivalent with:
 
<syntaxhighlight lang='java'>
jq '.a | .b | .c'
</syntaxhighlight>


=Organizatorium=
=Organizatorium=

Revision as of 19:30, 1 March 2019

Internal

Pipeline Content

The pipeline flows primitives, maps and arrays.

Individual strings flowing on a pipeline can be simulated with:

echo \"red\" \"blue\" \"green\" | jq '.'

This is how an array can be injected in the pipeline:

echo "[\"red\", \"blue\"]" | jq '.'

... and this is how a map can be injected in the pipeline:

echo "{\"size\": 10}" | jq '.'

Iteration

An iteration is pipeline content produced by the .[] filter, that converts and array into its individual elements.

Pipe Operator |

The pipe operator '|' combines two filters by feeding the output of the filter specified on the left into the input of the filter specified on the right.

If the left filter produces an iteration, the filter on the right is applied to each of the iteration elements.

Usually the "|" can be omitted on command line and it can be implied:

jq '.a.b.c'

is equivalent with:

jq '.a | .b | .c'

Organizatorium

Conversion from a map to an array.

Conversion from array to a map?