github.com/hugorut/terraform@v1.1.3/website/docs/language/functions/jsonencode.mdx (about) 1 --- 2 page_title: jsonencode - Functions - Configuration Language 3 description: The jsonencode function encodes a given value as a JSON string. 4 --- 5 6 # `jsonencode` Function 7 8 `jsonencode` encodes a given value to a string using JSON syntax. 9 10 The JSON encoding is defined in [RFC 7159](https://tools.ietf.org/html/rfc7159). 11 12 This function maps 13 [Terraform language values](/language/expressions/types) 14 to JSON values in the following way: 15 16 | Terraform type | JSON type | 17 | -------------- | --------- | 18 | `string` | String | 19 | `number` | Number | 20 | `bool` | Bool | 21 | `list(...)` | Array | 22 | `set(...)` | Array | 23 | `tuple(...)` | Array | 24 | `map(...)` | Object | 25 | `object(...)` | Object | 26 | Null value | `null` | 27 28 Since the JSON format cannot fully represent all of the Terraform language 29 types, passing the `jsonencode` result to `jsondecode` will not produce an 30 identical value, but the automatic type conversion rules mean that this is 31 rarely a problem in practice. 32 33 When encoding strings, this function escapes some characters using 34 Unicode escape sequences: replacing `<`, `>`, `&`, `U+2028`, and `U+2029` with 35 `\u003c`, `\u003e`, `\u0026`, `\u2028`, and `\u2029`. This is to preserve 36 compatibility with Terraform 0.11 behavior. 37 38 The `jsonencode` command outputs a minified representation of the input. 39 40 ## Examples 41 42 ``` 43 > jsonencode({"hello"="world"}) 44 {"hello":"world"} 45 ``` 46 47 ## Related Functions 48 49 * [`jsondecode`](/language/functions/jsondecode) performs the opposite operation, _decoding_ 50 a JSON string to obtain its represented value.