-
What I wantUsing yq V4, how to insert a key with an empty value in a yaml document? For example, I have the following document: a:
b:
c: "lorem ipsum" I would like to add a:
b:
c: "lorem ipsum"
d: Using yq v3With V3, I used to accomplish this with: yq w -i sample.yml a.d '' Using yq v4But, with V4, if I specify an empty string: yq -i eval '.a.d = ""' sample.yml I'll get something like this, which is not what I was expecting, because it inserts a string instead of a map: a:
b:
c: "lorem ipsum"
d: "" Is there a special operator to accomplish that? e.g. yq -i eval '.a.d = <empty>' sample.yml |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
That empty value is Whereas setting .a.d to "" sets it to the empty string. To set it to null you can:
But then you will see
Not as clean as v3 admittedly. |
Beta Was this translation helpful? Give feedback.
That empty value is
null
in yaml (one of the many ways you can represent null in yaml).Whereas setting .a.d to "" sets it to the empty string.
To set it to null you can:
But then you will see
null
in .a.d's value. To get an empty (null) value, you can do this:Not as clean as v3 admittedly.