Skip to content

HCL to JSON

Convert Terraform-style HCL configuration into equivalent JSON.

Input
Output

HCL to JSON

Paste HCL — the language Terraform, Packer and other HashiCorp tools use — and this converter returns the equivalent JSON. It handles the everyday shapes of a real .tf file: top-level attributes, and blocks with zero or more string labels such as resource "aws_instance" "web", nested inside other blocks as deep as your config goes. Labeled blocks convert using the same convention Terraform's own .tf.json syntax uses, so a resource with a type and a name lands under resource → type → name in the result, and repeated blocks at the same path — two ingress blocks inside one resource, say — become a JSON array instead of overwriting each other.

Strings, numbers, booleans, null, lists and inline object literals (tags = { Name = "web" }) all convert directly. Heredoc strings (<<EOT ... EOT and the indented <<-EOT form) become plain JSON strings with their line breaks kept, and ${var.name} interpolations — along with bare references like var.region or a call such as merge(a, b) — stay as literal text rather than being evaluated, since no browser tool can resolve Terraform variables or providers.

Options cover indent width (2 spaces, 4 spaces, tabs or minified), sorting keys alphabetically, keeping or discarding comments, and choosing between one merged JSON object or a flat list of blocks — each with its type, labels and body — for easier scripting. Duplicate attribute keys inside a block are flagged in the live tally rather than silently dropped, and Windows and Unix line endings are both accepted.

Everything runs locally in your browser — your configuration is never uploaded, which matters when it names real resources, IPs or account IDs. Copy the JSON, download it as a .txt file, or send it straight into another tool to keep working.

FAQ

Does this evaluate Terraform variables and functions?
No. Interpolations like ${var.region} and bare expressions such as var.region or merge(a, b) are kept as literal ${...} text in the output, exactly as Terraform's own JSON syntax represents them — this tool has no access to your variable values, state or providers.
How are blocks like resource "aws_instance" "web" represented?
By label, nested into the object: resource → aws_instance → web holds that block's attributes. It matches the convention Terraform itself uses for .tf.json files.
What happens to heredoc strings?
Both <<EOT and the indented <<-EOT form convert to a normal JSON string with real line breaks. The indented form has its common leading whitespace stripped first, matching how Terraform reads it.
Can I get a flat list of blocks instead of one big object?
Yes — switch "Output shape" to "List of blocks" to get an array of records, each with its type, labels and body, which is easier to loop over in a script.
Is my HCL configuration uploaded anywhere?
No. Conversion runs entirely in your browser — nothing you paste here, including resource names or values, ever leaves your device.