-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement yaml_decode with thanks to @djcode for most of the work.
- Loading branch information
1 parent
ae92ce1
commit 9dca0db
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
canonical: https://grafana.com/docs/alloy/latest/reference/stdlib/yaml_decode/ | ||
description: Learn about yaml_decode | ||
title: yaml_decode | ||
--- | ||
|
||
# yaml_decode | ||
|
||
The `yaml_decode` function decodes a string representing YAML into an {{< param "PRODUCT_NAME" >}} | ||
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 an {{< param "PRODUCT_NAME" >}} 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`]: ../../components/local.file/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters