jsonencode
The function that turns a Terraform value, such as a map or list, into a string of JSON text.
In more detail
It saves hand-quoting JSON and always produces valid output, which makes it ideal for policy documents and manifest files. Its partner jsondecode does the reverse, turning JSON text into a Terraform value.
Example
content = jsonencode({ environment = var.environment })Related terms
- JSON — A simple text format for structured data made of keys, values, lists and nested objects.
- built-in function — One of Terraform's fixed set of functions, such as lower(), join() or jsonencode(), that transform values inside expressions.
Taught in
- Parameterising With Input Variables — Infrastructure as Code with Terraform
- Return Values: Outputs And Locals — Infrastructure as Code with Terraform
- Functions And Expressions In HCL — Infrastructure as Code with Terraform
- Expressions And Functions: Making Configuration Compute — HashiCorp Terraform Associate (004) Exam Prep