Files
opentf/website/docs/configuration/functions/jsonencode.html.md
Nick Fagerlund d2abdc23ac website: Structural edit of configuration language docs
This commit is a wide-ranging set of edits to the pages under
/docs/configuration. Among other things, it

- Separates style conventions out into their own page.
- Separates type constraints and conversion info into their own page.
- Conflates similar complex types a little more freely, since the distinction is
  only relevant when restricting inputs for a reusable module or resource.
- Clarifies several concepts that confused me during edits.
2018-12-20 14:20:42 -08:00

1.3 KiB

layout, page_title, sidebar_current, description
layout page_title sidebar_current description
functions jsonencode function docs-funcs-encoding-jsonencode The jsonencode function encodes a given value as a JSON string.

jsonencode Function

jsonencode encodes a given value to a string using JSON syntax.

The JSON encoding is defined in RFC 7159.

This fucntion maps Terraform language values to JSON values in the following way:

Terraform type JSON type
string String
number Number
bool Bool
list(...) Array
set(...) Array
tuple(...) Array
map(...) Object
object(...) Object
Null value null

Since the JSON format cannot fully represent all of the Terraform language types, passing the jsonencode result to jsondecode will not produce an identical value, but the automatic type conversion rules mean that this is rarely a problem in practice.

Examples

> jsonencode({"hello"="world"})
{"hello":"world"}
  • jsondecode performs the opposite operation, decoding a JSON string to obtain its represented value.