github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/functions/jsonencode.html.md (about) 1 --- 2 layout: "functions" 3 page_title: "jsonencode - Functions - Configuration Language" 4 sidebar_current: "docs-funcs-encoding-jsonencode" 5 description: |- 6 The jsonencode function encodes a given value as a JSON string. 7 --- 8 9 # `jsonencode` Function 10 11 -> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and 12 earlier, see 13 [0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html). 14 15 `jsonencode` encodes a given value to a string using JSON syntax. 16 17 The JSON encoding is defined in [RFC 7159](https://tools.ietf.org/html/rfc7159). 18 19 This function maps 20 [Terraform language values](../expressions.html#types-and-values) 21 to JSON values in the following way: 22 23 | Terraform type | JSON type | 24 | -------------- | --------- | 25 | `string` | String | 26 | `number` | Number | 27 | `bool` | Bool | 28 | `list(...)` | Array | 29 | `set(...)` | Array | 30 | `tuple(...)` | Array | 31 | `map(...)` | Object | 32 | `object(...)` | Object | 33 | Null value | `null` | 34 35 Since the JSON format cannot fully represent all of the Terraform language 36 types, passing the `jsonencode` result to `jsondecode` will not produce an 37 identical value, but the automatic type conversion rules mean that this is 38 rarely a problem in practice. 39 40 ## Examples 41 42 ``` 43 > jsonencode({"hello"="world"}) 44 {"hello":"world"} 45 ``` 46 47 ## Related Functions 48 49 * [`jsondecode`](./jsondecode.html) performs the opposite operation, _decoding_ 50 a JSON string to obtain its represented value.