Read
This command can take a json file as input too, and will output yaml unless specified to export as json (-j)
Basic¶
Given a sample.yaml file of:
then
will output the value of '2'.
From Stdin¶
Given a sample.yaml file of:
will output the value of '2'.
Splat¶
Given a sample.yaml file of:
then
will output
Prefix Splat¶
Given a sample.yaml file of:
then
will output
Multiple Documents - specify a single document¶
Given a sample.yaml file of:
then
will output the value of '2'.
Multiple Documents - read all documents¶
Reading all documents will return the result as an array. This can be converted to json using the '-j' flag if desired.
Given a sample.yaml file of:
then
will output:
Arrays¶
You can give an index to access a specific element: e.g.: given a sample file of
then
will output 'sam'
Note that the path is in quotes to avoid the square brackets being interpreted by your shell.
Array Splat¶
e.g.: given a sample file of
then
will output:
Note that the path is in quotes to avoid the square brackets being interpreted by your shell.
Keys with dots¶
When specifying a key that has a dot use key lookup indicator.
Any valid yaml key can be specified as part of a key lookup.
Note that the path is in quotes to avoid the square brackets being interpreted by your shell.
Keys (and values) with leading dashes¶
If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error).
To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so:
Will result in
` --key: --value
Last updated