Synopsis¶
This functionality also referred to as YAML File validator; It helps to save your validated YAML online and Share it on social sites or emails. YAML Validator works well on Windows, MAC, Linux, Chrome, Firefox, Edge, and Safari. This YAML Linter helps a developer who works with JSON data to test and verify. Example to validate YAML. Espresso is a gorgeous Mac-only code editor that’s powerful and smooth, like the caffeinated beverage it’s named after. This text editor has been credited with helping its users edit CSS in less.
yq
takes YAML input, converts it to JSON, and pipes it to jq:
Like in jq
, you can also specify input filename(s) as arguments:
By default, no conversion of jq
output is done. Use the --yaml-output
/-y
option to convert it back into YAML:
Mapping key order is preserved. By default, custom YAML tags andstyles in the input are ignored. Use the --yaml-roundtrip
/-Y
option to preserve YAML tags and styles by representing them as extra items in their enclosing mappings and sequenceswhile in JSON:
Use the --width
/-w
option to pass the line wrap width for string literals. With -y/-Y
, files can be editedin place like with sed-i
: yq-yi.foo=1*.yml
. All other command line arguments are forwarded to jq
. yq
forwards the exit code jq
produced, unless there was an error in YAML parsing, in which case the exit code is 1.See the jq manual for more details on jq
features and options.
Because YAML treats JSON as a dialect of YAML, you can use yq to convert JSON to YAML: yq-y.<in.json>out.yml
.
Preserving tags and styles using the -Y
(--yaml-roundtrip
) option¶
The -Y
option helps preserve custom string styles andtags in your document. For example, consider the followingdocument (an AWS CloudFormation template fragment):
Passing this document through yq-y.Resources.ElasticLoadBalancer
will drop custom tags, such as !Ref
,and styles, such as the folded style of the Description
field:
Best Mac Editor For Yaml 2019
By contrast, passing it through yq-Y.Resources.ElasticLoadBalancer
will preserve tags and styles:
Best Mac Editor For Yaml 2020
To accomplish this in -Y
mode, yq carries extra metadata (mapping pairs and sequence values) in the JSONrepresentation of your document for any custom tags or styles that it finds. When converting the JSON back into YAML, itparses this metadata, re-applies the tags and styles, and discards the extra pairs and values.
Warning
The -Y
option is incompatible with jq filters that do not expect the extra information injected into the documentto preserve the YAML formatting. For example, a jq filter that counts entries in the Instances array will come up with4 entries instead of 2. A filter that expects all array entries to be mappings may break due to the presence of stringmetadata keys. Check your jq filter for compatibility/semantic validity when using the -Y
option.