Working with KYAML
Encode and decode to and from KYaml (a restricted subset of YAML that uses flow-style collections).
KYaml is useful when you want YAML data rendered in a compact, JSON-like form while still supporting YAML features like comments.
Notes:
Strings are always double-quoted in KYaml output.
Anchors and aliases are expanded (KYaml output does not emit them).
Encode kyaml: plain string scalar
Strings are always double-quoted in KYaml output.
Given a sample.yml file of:
cat
then
yq -o=kyaml '.' sample.ymlwill output
"cat"encode flow mapping and sequence
Given a sample.yml file of:
then
will output
encode non-string scalars
Given a sample.yml file of:
then
will output
quote non-identifier keys
Given a sample.yml file of:
then
will output
escape quoted strings
Given a sample.yml file of:
then
will output
preserve comments when encoding
Given a sample.yml file of:
then
will output
Encode kyaml: anchors and aliases
KYaml output does not support anchors/aliases; they are expanded to concrete values.
Given a sample.yml file of:
then
will output
Encode kyaml: yaml to kyaml shows formatting differences
KYaml uses flow-style collections (braces/brackets) and explicit commas.
Given a sample.yml file of:
then
will output
Encode kyaml: nested lists of objects
Lists and objects can be nested arbitrarily; KYaml always uses flow-style collections.
Given a sample.yml file of:
then
will output
Last updated