Adrien Delorme 193dad46e6
Hcl2 input variables, local variables and functions (#8588)
Mainly redefine or reused what Terraform did.

* allow to used `variables`, `variable` and `local` blocks
* import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
2020-02-06 11:49:21 +01:00

1.3 KiB

layout, page_title, sidebar_current, description
layout page_title sidebar_current description
docs jsonencode - Functions - Configuration Language configuration-functions-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 function maps Packer language values to JSON values in the following way:

Packer 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 Packer 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.