Skip to content

HCL to JSON converter

This HCL to JSON converter turns Terraform into JSON in your browser. Interpolations stay strings and are not evaluated.

This is a static parser, not terraform. Function calls and interpolations become strings. Invalid HCL is not repaired.

Ctrl+Enter or ⌘+Enter runs this tool immediately.

JSON output
HCL input
JSON output

Waiting for input.

Parsing stays in this browser. Input is not uploaded or saved.

How to use this tool

  1. Paste a Terraform file or a snippet, or load the sample variable and bucket.
  2. Read the JSON. Block labels become nested objects. type = string is the string string.
  3. If the status is an error, the output stays empty. Fix the HCL yourself.

What this conversion loses

  • Comments.
  • Evaluation of interpolations, functions, and traversals. They are copied as strings.
  • for expressions, which are rejected instead of being approximated.
  • Provider schemas, terraform console, and plan-time values.

Supported formats and limitations

  • One HCL body. This is not terraform json -generate or terraform show.
  • Labeled blocks nest as objects: resource.aws_s3_bucket.data. A second block with the same labels is an error.
  • Maps use key = value. Lists use brackets. Heredocs become strings.
  • Integers outside ±(2^53 − 1) are rejected. Non-finite numbers are rejected.
  • The parser does not load modules, backends, or .tf.json files as HCL.

Examples

A labeled resource

Labels become nested keys. Attributes become object fields.

resource "aws_s3_bucket" "data" {
  bucket = "configkit-data"
}

An interpolation stays a string

ami-${var.env} is not expanded.

resource "aws_instance" "web" {
  ami = "ami-${var.env}"
}

Common errors and solutions

Unterminated block
Add the missing }. The converter does not insert it.
for expressions are not converted
Write the map or list literally, or convert that expression in Terraform.
Duplicate block
Rename one of the blocks. This converter does not merge two resources with the same type and name.

FAQ

How does this HCL to JSON converter handle interpolations?
They are copied as strings. Function calls and traversals are not evaluated. for expressions are rejected instead of being approximated.
Can I convert Terraform to JSON online and apply it?
Terraform reads .tf.json. Traversals that were copied as strings may not be valid JSON-syntax Terraform. Review the output.
Why is type a string instead of a type expression?
JSON cannot hold a Terraform type. The identifier string is written as the string string.
Is the .tf file uploaded?
No. It is parsed in your browser. It is not sent to Terraform Cloud or an application server.

Privacy check

Open DevTools → Network, paste a document, and confirm no request carries the editor text. The page load and the Google tag still appear. Analytics events carry the tool name, never what you pasted.

Read next

Related tools

  • JSON to TOML converter

    Convert a JSON object to TOML in the browser. Null values and mixed arrays are rejected, and invalid JSON produces no TOML.

  • TOML to JSON online

    Convert TOML to JSON online in your browser. Tables, arrays, and dates are mapped explicitly; the file is not uploaded.

  • YAML to JSON without uploading

    Convert YAML to JSON without uploading the file. Parsing stays in this browser and works offline after the page loads.