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