From d4076588575bd5a223e2836e7b37669d04170ffe Mon Sep 17 00:00:00 2001 From: Daniel Jolly Date: Mon, 5 Feb 2024 16:14:27 -0500 Subject: [PATCH 1/3] Adding documentation for yaml_decode --- .../flow/reference/stdlib/yaml_decode.md | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 docs/sources/flow/reference/stdlib/yaml_decode.md diff --git a/docs/sources/flow/reference/stdlib/yaml_decode.md b/docs/sources/flow/reference/stdlib/yaml_decode.md new file mode 100644 index 000000000000..b922aeb11460 --- /dev/null +++ b/docs/sources/flow/reference/stdlib/yaml_decode.md @@ -0,0 +1,48 @@ +--- +aliases: +- ../../configuration-language/standard-library/yaml_decode/ +- /docs/grafana-cloud/agent/flow/reference/stdlib/yaml_decode/ +- /docs/grafana-cloud/monitor-infrastructure/agent/flow/reference/stdlib/yaml_decode/ +- /docs/grafana-cloud/monitor-infrastructure/integrations/agent/flow/reference/stdlib/yaml_decode/ +- /docs/grafana-cloud/send-data/agent/flow/reference/stdlib/yaml_decode/ +canonical: https://grafana.com/docs/agent/latest/flow/reference/stdlib/yaml_decode/ +description: Learn about yaml_decode +title: yaml_decode +--- + +# yaml_decode + +The `yaml_decode` function decodes a string representing YAML into a River +value. `yaml_decode` fails if the string argument provided cannot be parsed as +YAML. + +A common use case of `yaml_decode` is to decode the output of a +[`local.file`][] component to a River value. + +> Remember to escape double quotes when passing YAML string literals to `yaml_decode`. +> +> For example, the YAML value `key: "value"` is properly represented by the +> string `"key: \"value\""`. + +## Examples + +``` +> yaml_decode("15") +15 + +> yaml_decode("[1, 2, 3]") +[1, 2, 3] + +> yaml_decode("null") +null + +> yaml_decode("key: value") +{ + key = "value", +} + +> yaml_decode(local.file.some_file.content) +"Hello, world!" +``` + +[`local.file`]: {{< relref "../components/local.file.md" >}} From 9c3522d6e1e8fc4b3a2b0cc2da36e11f1f3aaee1 Mon Sep 17 00:00:00 2001 From: Daniel Jolly Date: Mon, 5 Feb 2024 16:25:04 -0500 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53c8aafb81e5..3c3e6f5800b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,8 @@ Main (unreleased) - Updated dependency to add support for Go 1.22 (@stefanb) +- Added documentation for `yaml_decode` stdlib function (@djcode) + v0.39.2 (2024-1-31) -------------------- From 8362224139c1faf73af4f7aaa342bfd6329ea2ce Mon Sep 17 00:00:00 2001 From: Daniel Jolly Date: Tue, 6 Feb 2024 16:24:48 -0500 Subject: [PATCH 3/3] Update docs/sources/flow/reference/stdlib/yaml_decode.md Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com> --- docs/sources/flow/reference/stdlib/yaml_decode.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/sources/flow/reference/stdlib/yaml_decode.md b/docs/sources/flow/reference/stdlib/yaml_decode.md index b922aeb11460..fa72b16e056c 100644 --- a/docs/sources/flow/reference/stdlib/yaml_decode.md +++ b/docs/sources/flow/reference/stdlib/yaml_decode.md @@ -19,10 +19,11 @@ YAML. A common use case of `yaml_decode` is to decode the output of a [`local.file`][] component to a River value. -> Remember to escape double quotes when passing YAML string literals to `yaml_decode`. -> -> For example, the YAML value `key: "value"` is properly represented by the -> string `"key: \"value\""`. +{{< admonition type="tip" >}} +Remember to escape double quotes when passing YAML string literals to `yaml_decode`. + +For example, the YAML value `key: "value"` is properly represented by the string `"key: \"value\""`. +{{< /admonition >}} ## Examples