y
y
yq
Search…
y
y
yq
v4.x
yq
How It Works
Upgrading from V3
Commands
Evaluate
Evaluate All
Shell Completion
Operators
Add
Alternative (Default value)
Anchor and Alias Operators
Assign (Update)
Boolean Operators
Collect into Array
Column
Comment Operators
Compare Operators
Contains
Create, Collect into Object
Date Time
Delete
Document Index
Encode / Decode
Entries
Env Variable Operators
Equals
Eval
File Operators
Flatten
Group By
Has
Keys
Length
Line
Load
Map
Multiply (Merge)
Parent
Path
Pick
Pipe
Recursive Descent (Glob)
Reduce
Reverse
Select
Sort
Sort Keys
Split into Documents
String Operators
Style
Subtract
Tag
Traverse (Read)
Union
Unique
Variable Operators
With
Usage
Output format
Working with CSV, TSV
Working with JSON
Working with Properties
Working with XML
Front Matter
Split into multiple files
GitHub Action
Tips, Tricks, Troubleshooting
Github Page
Powered By
GitBook
Load
The load operators allows you to load in content from another file.
Note that you can use string operators like
+
and
sub
to modify the value in the yaml file to a path that exists in your system.
You can load files of the following supported types:
Format
Load Operator
Yaml
load
XML
load_xml
Properties
load_props
Plain String
load_str
Base64
load_base64
Samples files for tests:
yaml
../../examples/thing.yml
:
1
a
:
apple is included
2
b
:
cool
Copied!
xml
small.xml
:
1
<
this
>
is some xml
</
this
>
Copied!
properties
small.properties
:
1
this.is
=
a properties file
Copied!
base64
base64.txt
:
1
bXkgc2VjcmV0IGNoaWxsaSByZWNpcGUgaXMuLi4u
Copied!
Note that versions prior to 4.18 require the 'eval/e' command to be specified.
yq e <exp> <file>
Simple example
Given a sample.yml file of:
1
myFile
:
../../examples/thing.yml
Copied!
then
1
yq
'load(.myFile)'
sample.yml
Copied!
will output
1
a
:
apple is included
2
b
:
cool.
Copied!
Replace node with referenced file
Note that you can modify the filename in the load operator if needed.
Given a sample.yml file of:
1
something
:
2
file
:
thing.yml
Copied!
then
1
yq
'.something |= load("../../examples/" + .file)'
sample.yml
Copied!
will output
1
something
:
2
a
:
apple is included
3
b
:
cool.
Copied!
Replace
all
nodes with referenced file
Recursively match all the nodes (
..
) and then filter the ones that have a 'file' attribute.
Given a sample.yml file of:
1
something
:
2
file
:
thing.yml
3
over
:
4
here
:
5
-
file
:
thing.yml
Copied!
then
1
yq
'(.. | select(has("file"))) |= load("../../examples/" + .file)'
sample.yml
Copied!
will output
1
something
:
2
a
:
apple is included
3
b
:
cool.
4
over
:
5
here
:
6
-
a
:
apple is included
7
b
:
cool.
Copied!
Replace node with referenced file as string
This will work for any text based file
Given a sample.yml file of:
1
something
:
2
file
:
thing.yml
Copied!
then
1
yq
'.something |= load_str("../../examples/" + .file)'
sample.yml
Copied!
will output
1
something
:
|-
2
a
:
apple is included
3
b
:
cool.
Copied!
Load from XML
Given a sample.yml file of:
1
cool
:
things
Copied!
then
1
yq
'.more_stuff = load_xml("../../examples/small.xml")'
sample.yml
Copied!
will output
1
cool
:
things
2
more_stuff
:
3
this
:
is some xml
Copied!
Load from Properties
Given a sample.yml file of:
1
cool
:
things
Copied!
then
1
yq
'.more_stuff = load_props("../../examples/small.properties")'
sample.yml
Copied!
will output
1
cool
:
things
2
more_stuff
:
3
this
:
4
is
:
a properties file
Copied!
Merge from properties
This can be used as a convenient way to update a yaml document
Given a sample.yml file of:
1
this
:
2
is
:
from yaml
3
cool
:
ay
Copied!
then
1
yq
'. *= load_props("../../examples/small.properties")'
sample.yml
Copied!
will output
1
this
:
2
is
:
a properties file
3
cool
:
ay
Copied!
Load from base64 encoded file
Given a sample.yml file of:
1
cool
:
things
Copied!
then
1
yq
'.more_stuff = load_base64("../../examples/base64.txt")'
sample.yml
Copied!
will output
1
cool
:
things
2
more_stuff
:
my secret chilli recipe is
...
.
Copied!
Previous
Line
Next
Map
Last modified
4mo ago
Copy link
Contents
Samples files for tests:
yaml
xml
properties
base64
Simple example
Replace node with referenced file
Replace all nodes with referenced file
Replace node with referenced file as string
Load from XML
Load from Properties
Merge from properties
Load from base64 encoded file