Encode / Decode
Encode operators will take the piped in object structure and encode it as a string in the desired format. The decode operators do the opposite, they take a formatted string and decode it into the relevant object structure.
Note that you can optionally pass an indent value to the encode functions (see below).
These operators are useful to process yaml documents that have stringified embedded yaml/json/props in them.
Yaml
from_yaml/@yamld
to_yaml(i)/@yaml
JSON
from_json/@jsond
to_json(i)/@json
Properties
from_props/@propsd
to_props/@props
CSV
from_csv/@csvd
to_csv/@csv
TSV
from_tsv/@tsvd
to_tsv/@tsv
XML
from_xml/@xmld
to_xml(i)/@xml
Base64
@base64d
@base64
URI
@urid
@uri
Shell
@sh
See CSV and TSV documentation for accepted formats.
XML uses the --xml-attribute-prefix
and xml-content-name
flags to identify attributes and content fields.
Base64 assumes rfc4648 encoding. Encoding and decoding both assume that the content is a utf-8 string and not binary content.
Encode value as json string
Given a sample.yml file of:
then
will output
Encode value as json string, on one line
Pass in a 0 indent to print json on a single line.
Given a sample.yml file of:
then
will output
Encode value as json string, on one line shorthand
Pass in a 0 indent to print json on a single line.
Given a sample.yml file of:
then
will output
Decode a json encoded string
Keep in mind JSON is a subset of YAML. If you want idiomatic yaml, pipe through the style operator to clear out the JSON styling.
Given a sample.yml file of:
then
will output
Encode value as props string
Given a sample.yml file of:
then
will output
Decode props encoded string
Given a sample.yml file of:
then
will output
Decode csv encoded string
Given a sample.yml file of:
then
will output
Decode tsv encoded string
Given a sample.yml file of:
then
will output
Encode value as yaml string
Indent defaults to 2
Given a sample.yml file of:
then
will output
Encode value as yaml string, with custom indentation
You can specify the indentation level as the first parameter.
Given a sample.yml file of:
then
will output
Decode a yaml encoded string
Given a sample.yml file of:
then
will output
Update a multiline encoded yaml string
Given a sample.yml file of:
then
will output
Update a single line encoded yaml string
Given a sample.yml file of:
then
will output
Encode array of scalars as csv string
Scalars are strings, numbers and booleans.
Given a sample.yml file of:
then
will output
Encode array of arrays as csv string
Given a sample.yml file of:
then
will output
Encode array of arrays as tsv string
Scalars are strings, numbers and booleans.
Given a sample.yml file of:
then
will output
Encode value as xml string
Given a sample.yml file of:
then
will output
Encode value as xml string on a single line
Given a sample.yml file of:
then
will output
Encode value as xml string with custom indentation
Given a sample.yml file of:
then
will output
Decode a xml encoded string
Given a sample.yml file of:
then
will output
Encode a string to base64
Given a sample.yml file of:
then
will output
Encode a yaml document to base64
Pipe through @yaml first to convert to a string, then use @base64 to encode it.
Given a sample.yml file of:
then
will output
Encode a string to uri
Given a sample.yml file of:
then
will output
Decode a URI to a string
Given a sample.yml file of:
then
will output
Encode a string to sh
Sh/Bash friendly string
Given a sample.yml file of:
then
will output
Decode a base64 encoded string
Decoded data is assumed to be a string.
Given a sample.yml file of:
then
will output
Decode a base64 encoded yaml document
Pipe through from_yaml
to parse the decoded base64 string as a yaml document.
Given a sample.yml file of:
then
will output
Last updated