Skip to main content

HCL to JSON Converter

Convert Terraform HCL configuration to its equivalent JSON representation, following Terraform's documented JSON syntax mapping — nested blocks, labels, repeated blocks, lists, maps and heredocs. Non-literal expressions (references, function calls) are preserved as `${...}` interpolation strings. Runs entirely in your browser.

Input

Drop a file or browse
One file · text
Or

Output

JSON output
 
Was this helpful?

Guides

Paste Terraform HCL (HashiCorp Configuration Language), get its equivalent JSON representation — the same shape Terraform itself uses for .tf.json files. Nested blocks, block labels, repeated blocks, lists, maps and heredocs all convert following Terraform's documented JSON syntax mapping. Conversion happens as you type, with no upload and no sign-up.

How to use it

  1. Paste your Terraform (.tf) source into the input box, or upload a file — its contents drop straight into the editor.
  2. Pick an indent size (2 spaces, 4 spaces, or minified) from the Options section.
  3. The JSON output appears instantly on the right, syntax-highlighted.
  4. Copy it, or download it as a .tf.json file.

A block's type name becomes a JSON object key. Each label on the block (resource "aws_instance" "web" has two: the type and the name) nests one JSON object level deeper. A block type that repeats with no labels (two network_interface { ... } blocks in the same resource) becomes a JSON array of bodies instead. Lists ([...]), inline maps ({...}), and heredoc strings (<<EOF ... EOF, <<-EOF ... EOF) all convert to their direct JSON equivalents.

What happens to references and function calls, like var.instance_type or data.aws_ami.ubuntu.id?

Anything that isn't a literal value — a variable reference, a resource attribute reference, a function call, an arithmetic or boolean expression, a for comprehension like [for s in var.list : s.id] — gets wrapped as a JSON string using the same ${...} interpolation syntax Terraform uses for expressions inside a native-syntax string, e.g. "instance_type": "${var.instance_type}". This matches how you'd write that same expression by hand in a real .tf.json file, and it's exactly what the sibling JSON to HCL Converter unwraps back into a raw expression.

Does it distinguish a block from a map attribute?

Not with certainty — and neither would any tool without your provider's schema. A nested block with no labels (like lifecycle { create_before_destroy = true }) and a literal map attribute (like tags = { Name = "web" }) both convert to a plain JSON object at that key, because that's genuinely how Terraform's own JSON syntax represents both. Real Terraform only tells them apart using the resource type's schema at apply time — this converter doesn't have that schema, so it emits the structural JSON either way, which is what you want for inspecting or diffing a config's shape.

Is my Terraform config private?

Completely. Tokenizing, parsing, and conversion all run locally in your browser — your HCL source, including any secrets or hostnames in it, is never sent to a server.

Need the other direction, or just to format HCL?

Use the JSON to HCL Converter to go from Terraform JSON back to native syntax, or the Terraform Formatter if you just want to clean up indentation and argument order without changing the format.

terraformhcljsontf.jsoninfrastructure as codeiacdevopsconfighcl2json

Use it from code

From 3 credits per call

REST API

curl -X POST https://api.iotools.cloud/v1/tool/hcl-to-json-converter \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "hclSource": "resource \"aws_instance\" \"web\" {\n  ami           …",
    "indent": "2"
  }'

Swap in your own key from your account. The tool's fields are the body — no wrapper.

Ask an AI agent

Use the IOTools `hcl-to-json-converter` tool (HCL to JSON Converter) on this input:

YOUR_INPUT_HERE

Paste this at any agent connected to the IOTools MCP server, then add your input.

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.