You can use terraform jsonencode() and jsondecode() functions to encode and decode JSON data. jsonencode() encodes a given value to a string using JSON syntax and jsondecode() interprets a given string as JSON, returning a representation of the result of decoding that string.
Syntax: jsonencode(string) jsondecode(string)
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
## Open terraform console terraform console ## Encode a string into json jsonencode({"name": "debjeet", "skills": ["cloud", "devops"]}) ## returns ## {\"name\":\"debjeet\",\"skills\":[\"cloud\",\"devops\"]} ## Decode a json string jsondecode("{\"name\":\"debjeet\",\"skills\":[\"cloud\",\"devops\"]}") ## returns ## { ## "name" = "debjeet" ## "skills" = [ ## "cloud", ## "devops", ## ] ## } |