Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for proposed yaml_decode function #6315

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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)
--------------------

Expand Down
49 changes: 49 additions & 0 deletions docs/sources/flow/reference/stdlib/yaml_decode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
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.

{{< 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

```
> 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" >}}
Loading