2018-05-13 19:40:57 +02:00
|
|
|
---
|
|
|
|
layout: "functions"
|
2018-12-20 05:35:11 +01:00
|
|
|
page_title: "jsondecode - Functions - Configuration Language"
|
2018-05-13 19:40:57 +02:00
|
|
|
sidebar_current: "docs-funcs-encoding-jsondecode"
|
|
|
|
description: |-
|
|
|
|
The jsondecode function decodes a JSON string into a representation of its
|
|
|
|
value.
|
|
|
|
---
|
|
|
|
|
|
|
|
# `jsondecode` Function
|
|
|
|
|
2019-01-17 01:33:57 +01:00
|
|
|
-> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and
|
|
|
|
earlier, see
|
|
|
|
[0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html).
|
|
|
|
|
2018-05-13 19:40:57 +02:00
|
|
|
`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
|
2019-03-01 01:15:20 +01:00
|
|
|
[Terraform language values](../expressions.html#types-and-values)
|
2018-05-13 19:40:57 +02:00
|
|
|
in the following way:
|
|
|
|
|
|
|
|
| JSON type | Terraform 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 Terraform language `null` value |
|
|
|
|
|
|
|
|
The Terraform 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`](./jsonencode.html) performs the opposite operation, _encoding_
|
|
|
|
a value as JSON.
|