Back to Yq

Encoder / Decoder

pkg/yqlib/doc/operators/headers/encode-decode.md

4.53.21.2 KB
Original Source

Encoder / Decoder

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.

FormatDecode (from string)Encode (to string)
Yamlfrom_yaml/@yamldto_yaml(i)/@yaml
JSONfrom_json/@jsondto_json(i)/@json
Propertiesfrom_props/@propsdto_props/@props
CSVfrom_csv/@csvdto_csv/@csv
TSVfrom_tsv/@tsvdto_tsv/@tsv
XMLfrom_xml/@xmldto_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.