mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-20 10:19:27 -05:00
Signed-off-by: Janos <86970079+janosdebugs@users.noreply.github.com> Signed-off-by: Damian Stasik <920747+damianstasik@users.noreply.github.com> Signed-off-by: Roman Grinovski <roman.grinovski@gmail.com> Co-authored-by: Damian Stasik <920747+damianstasik@users.noreply.github.com> Co-authored-by: Roman Grinovski <roman.grinovski@gmail.com>
47 lines
1.5 KiB
Plaintext
47 lines
1.5 KiB
Plaintext
---
|
|
sidebar_label: jsondecode
|
|
description: |-
|
|
The jsondecode function decodes a JSON string into a representation of its
|
|
value.
|
|
---
|
|
|
|
# `jsondecode` Function
|
|
|
|
`jsondecode` interprets a given string as JSON, returning a representation
|
|
of the result of decoding that string.
|
|
|
|
The JSON encoding is defined in [RFC 7159](https://tools.ietf.org/html/rfc7159).
|
|
|
|
This function maps JSON values to
|
|
[OpenTofu language values](../../language/expressions/types.mdx)
|
|
in the following way:
|
|
|
|
| JSON type | OpenTofu type |
|
|
| --------- | ------------------------------------------------------------ |
|
|
| String | `string` |
|
|
| Number | `number` |
|
|
| Boolean | `bool` |
|
|
| Object | `object(...)` with attribute types determined per this table |
|
|
| Array | `tuple(...)` with element types determined per this table |
|
|
| Null | The OpenTofu language `null` value |
|
|
|
|
The OpenTofu language automatic type conversion rules mean that you don't
|
|
usually need to worry about exactly what type is produced for a given value,
|
|
and can just use the result in an intuitive way.
|
|
|
|
## Examples
|
|
|
|
```
|
|
> jsondecode("{\"hello\": \"world\"}")
|
|
{
|
|
"hello" = "world"
|
|
}
|
|
> jsondecode("true")
|
|
true
|
|
```
|
|
|
|
## Related Functions
|
|
|
|
* [`jsonencode`](../../language/functions/jsonencode.mdx) performs the opposite operation, _encoding_
|
|
a value as JSON.
|