HCL Converter
Convert Terraform-style HCL into JSON or flat configuration text, with path and type checks that expose lossy handoffs before reuse.{{ summaryHeading }}
{{ chartMessage }}
| Path | Type | Value preview | Copy |
|---|---|---|---|
| {{ row[0] }} | {{ row[1] }} | {{ row[2] }} | |
| No scalar paths are available. | |||
HashiCorp Configuration Language (HCL) is written for people to read and edit, while still carrying structured blocks, arguments, expressions, lists, and maps. Terraform configuration is the best-known use, but the same language model also appears in tools such as Nomad and Packer.
Changing HCL into another syntax is not the same as evaluating it. A literal string or number can move cleanly into JSON or YAML. An expression such as a resource reference still depends on the program that will evaluate the configuration, so a generic conversion can preserve its parsed representation without resolving its runtime value.
- Argument
- A named value assignment inside a body, such as a region or version constraint.
- Block
- A nested configuration object with a type, optional labels, and its own body.
- Expression
- A value that may be literal or may refer to variables, resources, functions, or other runtime context.
Hierarchical targets such as JSON and YAML can retain nested objects and arrays. Flat key-value targets such as environment variables, INI, and properties must compress that hierarchy into paths. The chosen separator, key casing, and prefix then become part of the interface consumed by scripts or applications.
The main risk is semantic drift. A converted file may be syntactically tidy while still being unsuitable for the destination because HCL expressions, repeated blocks, types, or long values do not have a direct equivalent. Treat conversion as a reviewable projection of the parsed configuration, not as proof that Terraform or another HCL application will accept the result.
How to Use This Tool:
Choose the destination based on whether it can retain the source hierarchy or needs flat keys.
- Paste HCL source or load one supported local configuration file. Correct any HCL parse error before judging the output.
- Select Output format. Use JSON or YAML when nested structure matters; use environment variables, INI, or properties only for a deliberate flat handoff.
- Set the flattening convention when needed. Dot or slash paths change the ledger, while the ENV prefix and uppercase choice change generated environment keys.
- Review Converted configuration and Flattened path ledger. Compare expression-bearing values and repeated blocks with the HCL source before using the result.
Interpreting Results:
The parsed root type, key count, scalar count, maximum depth, and value-type distribution describe the structure that survived parsing. They do not establish that the configuration is valid for Terraform, Nomad, Packer, or any provider schema.
Use the path ledger to spot unexpected nesting, array positions, or key normalization. For flat targets, compare a few generated keys with what the receiving application actually expects. Any warning about expression semantics means the output needs destination-specific review before deployment.
Technical Details:
HCL syntax is parsed into a document tree before any target text is generated. The converter serializes that tree deterministically; it does not run Terraform evaluation, resolve references, load variables, expand functions, or apply provider schemas.
Transformation Core:
| Stage | Rule | Consequence |
|---|---|---|
| Parse | Read one or more HCL documents into objects, arrays, and scalar values. | Invalid syntax stops conversion; expressions remain in the parser's representation. |
| Walk | Visit nested objects and arrays, count keys and depth, and emit one path for each scalar. | The path ledger makes repeated blocks and array positions visible. |
| Project | Keep the parsed hierarchy for JSON or YAML, or turn scalar paths into flat keys for ENV, INI, and properties. | Flat targets lose hierarchy and may rename keys. |
| Serialize | Apply the chosen indentation, path style, prefix, and ENV key case. | Repeated runs are comparable only when these settings remain the same. |
Flat-Key Rule Core:
| Target or setting | Mapping rule |
|---|---|
| Dot paths | Object keys use dots; array positions use bracketed indexes. Keys that are not simple identifiers use a quoted bracket form. |
| Slash paths | Each object key or array index becomes a slash-separated segment; literal slashes in keys are escaped. |
| ENV | Path separators and unsupported characters become underscores. An optional normalized prefix is prepended, and keys may be uppercased. |
| INI | The first path segment becomes a lowercase section; the remaining segments become one lowercase underscore-separated key. |
| Properties | The selected flattened path is written directly before the equals sign. |
JSON, YAML, ENV, INI, and properties serialization use the complete parsed values. Only the ledger’s labeled value previews shorten scalar text longer than 120 characters with an ellipsis. Flat formats still change hierarchy and key names, and all targets require review of destination-specific expression semantics.
Source text is limited to 200,000 characters, and a loaded file may be no larger than 2 MiB. JSON spacing accepts minified, two-space, or four-space output; YAML uses two or four spaces. The path preview can show 10 through 500 rows, while the generated target text is not shortened by that preview-row setting.
Privacy Notes:
HCL source is read and converted in the browser rather than uploaded for conversion. Local processing protects the source from a conversion service, but copied or downloaded output can still contain credentials, addresses, account identifiers, and other sensitive configuration values. Review the destination and remove secrets before sharing.
Worked Examples:
Reviewing a Terraform resource
A resource block with nested tags is converted to JSON. The tag map remains nested, while a resource reference appears in its parsed expression form. Running terraform validate in the real configuration directory is still required because conversion does not load modules or provider schemas.
Preparing environment keys
A small variables file is converted to ENV with prefix APP and uppercase keys. The path ledger is checked first so two different HCL paths do not become confusingly similar underscore-separated names in the receiving application.
References:
- HCL native syntax specification, HashiCorp.
- Terraform configuration syntax, HashiCorp Developer.
- terraform validate command reference, HashiCorp Developer.