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

29 lines
1.2 KiB
Markdown
Raw Normal View History

2021-11-03 02:54:09 +00:00
# Encoder / Decoder
2021-10-22 01:37:47 +00:00
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.
2021-10-22 03:55:58 +00:00
2021-10-26 03:33:57 +00:00
Note that you can optionally pass an indent value to the encode functions (see below).
2022-05-24 08:18:27 +00:00
These operators are useful to process yaml documents that have stringified embedded yaml/json/props in them.
2021-12-02 01:11:15 +00:00
| Format | Decode (from string) | Encode (to string) |
| --- | -- | --|
2022-08-01 04:12:35 +00:00
| 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 |
2022-08-01 04:12:35 +00:00
| XML | from_xml/@xmld | to_xml(i)/@xml |
2022-02-22 22:26:35 +00:00
| Base64 | @base64d | @base64 |
2023-01-23 00:37:18 +00:00
| URI | @urid | @uri |
2023-02-02 01:22:52 +00:00
| Shell | | @sh |
2021-12-02 01:11:15 +00:00
See CSV and TSV [documentation](https://mikefarah.gitbook.io/yq/usage/csv-tsv) for accepted formats.
2021-12-02 01:11:15 +00:00
2021-12-21 05:52:54 +00:00
XML uses the `--xml-attribute-prefix` and `xml-content-name` flags to identify attributes and content fields.
2022-02-22 22:26:35 +00:00
Base64 assumes [rfc4648](https://rfc-editor.org/rfc/rfc4648.html) encoding. Encoding and decoding both assume that the content is a string.