How to encode and decode JSON data in terraform?

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)