Add
Add behaves differently according to the type of the LHS:
arrays: concatenate
number scalars: arithmetic addition
string scalars: concatenate
maps: shallow merge (use the multiply operator (
*
) to deeply merge)
Use +=
as a relative append assign for things like increment. Note that .a += .x
is equivalent to running .a = .a + .x
.
Concatenate arrays
Given a sample.yml file of:
then
will output
Concatenate to existing array
Note that the styling of a
is kept.
Given a sample.yml file of:
then
will output
Concatenate null to array
Given a sample.yml file of:
then
will output
Append to existing array
Note that the styling is copied from existing array elements
Given a sample.yml file of:
then
will output
Prepend to existing array
Given a sample.yml file of:
then
will output
Add new object to array
Given a sample.yml file of:
then
will output
Relative append
Given a sample.yml file of:
then
will output
String concatenation
Given a sample.yml file of:
then
will output
Number addition - float
If the lhs or rhs are floats then the expression will be calculated with floats.
Given a sample.yml file of:
then
will output
Number addition - int
If both the lhs and rhs are ints then the expression will be calculated with ints.
Given a sample.yml file of:
then
will output
Increment numbers
Given a sample.yml file of:
then
will output
Date addition
You can add durations to dates. Assumes RFC3339 date time format, see date-time operators for more information.
Given a sample.yml file of:
then
will output
Date addition - custom format
You can add durations to dates. See date-time operators for more information.
Given a sample.yml file of:
then
will output
Add to null
Adding to null simply returns the rhs
Running
will output
Add maps to shallow merge
Adding objects together shallow merges them. Use *
to deeply merge.
Given a sample.yml file of:
then
will output
Custom types: that are really strings
When custom tags are encountered, yq will try to decode the underlying type.
Given a sample.yml file of:
then
will output
Custom types: that are really numbers
When custom tags are encountered, yq will try to decode the underlying type.
Given a sample.yml file of:
then
will output
Last updated