JSON to HCL Converter
Convert JSON to Terraform HCL (HashiCorp Configuration Language).
or drop a file here
About JSON to HCL Converter
Convert JSON configuration files to Terraform HCL (HashiCorp Configuration Language) format. Supports Terraform resource blocks, variable declarations, module definitions, data sources, and provider configurations. Nested objects are converted to HCL block syntax, while primitive values and arrays use standard HCL attribute assignment.
Built and maintained by Meet Shah · Last updated
What this tool is used for
- Converting a JSON infrastructure definition into readable Terraform syntax.
- Turning a provider's JSON example into HCL you can commit.
- Producing HCL from a generated JSON config.
- Getting a starting point for a resource block from an API response.
- Comparing Terraform's own JSON syntax against the HCL form.
Frequently Asked Questions
- Why convert JSON to HCL rather than using Terraform's JSON syntax?
- Because the JSON form has no comments, no heredocs and no expressions, and it is significantly harder to read at review time. Terraform accepts both, so the JSON variant is best kept for machine-generated files and HCL for anything a person maintains.
- How are JSON types mapped?
- Strings stay quoted, numbers and booleans become bare literals, arrays become bracketed lists, and nested objects become either blocks or object literals depending on context. HCL has no null, so a JSON null becomes an omitted attribute rather than an explicit value.
- What cannot be inferred from the JSON?
- Block labels and whether a nested object should be a block or an attribute — both are schema decisions. JSON has one way to nest and HCL has two, so a conversion produces a plausible reading that has to be checked against the provider's expected shape.
- How do interpolations survive the conversion?
- They do not, because JSON has no concept of them — a `${var.name}` inside a JSON string is just characters. The converted output contains the literal text, and turning it back into a real expression is a manual step the conversion cannot make for you.
- Is the output valid Terraform?
- It is valid HCL, which is not the same thing. `terraform validate` checks it against the provider schema, and that is the step that catches a block written as an attribute or a missing required label. Treat the conversion as a syntax translation, not a schema-aware one.
Common errors and gotchas
- Assuming the output is valid Terraform. Block labels and provider schema requirements are not in the JSON.
- Losing the argument-versus-block distinction, which HCL makes and JSON does not.
- Producing identifiers that HCL rejects, such as keys containing a dash.
- Overlooking that Terraform accepts JSON directly, so the conversion may be unnecessary.
- Converting an interpolation string literally, where HCL expression syntax differs.
Related Converters tools
JSON to YAML
Convert JSON into clean, readable YAML instantly.
YAML to JSON
Convert YAML configuration into valid JSON.
JSON to XML
Convert JSON structures into nested XML markup.
HWB to HEX Converter
Convert an HWB color to HEX.
JSON to SQL
Turn a JSON array of objects into SQL INSERT statements.
CSV to XML
Convert CSV rows into structured XML records.
XML to CSV
Flatten repeated XML records into CSV rows.
INI to JSON
Parse INI config sections and keys into JSON.