HCL ↔ JSON Converter

Convert between Terraform HCL and JSON formats with real-time parsing, syntax highlighting, and tree view.

About This Tool

The HCL to JSON Converter is a free, browser-based tool that transforms data between HashiCorp Configuration Language (HCL) and JSON formats in real time. HCL is the native configuration language used by Terraform, Packer, Vault, Consul, Nomad, and Waypoint. This converter lets you quickly translate between HCL's human-friendly syntax and JSON's machine-readable format, which is essential when working with Terraform's JSON configuration syntax, CI/CD pipelines, or programmatic infrastructure management.

The parser handles all core HCL constructs: resource, variable, output, data, locals, module, provider, and terraform blocks. It supports attributes with string, number, boolean, list, and map values, nested blocks, string interpolation expressions like ${var.name}, and heredoc strings. When converting from JSON back to HCL, known block types are automatically reconstructed with proper block syntax rather than appearing as plain key-value pairs.

The tool provides syntax highlighting for both HCL and JSON output, coloring block keywords, strings, numbers, booleans, function calls, and reference expressions like var.region or local.tags. A tree view mode lets you explore the parsed JSON structure interactively, expanding and collapsing nested objects and arrays. Error messages include line numbers when available so you can quickly locate issues in your HCL input.

All processing happens entirely in your browser. Your Terraform configurations never leave your machine — there are no server round-trips, no logging, and no third-party services. This makes it safe to convert configurations containing sensitive values like database credentials, API keys, or infrastructure secrets. The tool is particularly useful alongside the JSON ↔ YAML Converter for multi-format workflows, the TOML ↔ JSON Converter for similar configuration file conversions, and the YAML Formatter when working with Kubernetes manifests alongside Terraform.

How to Use

  1. Select the conversion direction using the HCL → JSON or JSON → HCL toggle button at the top.
  2. Paste or type your configuration into the Input panel on the left. Alternatively, click one of the Preset buttons (AWS EC2 Instance, Variable Definitions, S3 Bucket, VPC Network) to load a sample.
  3. The converted output appears instantly in the Output panel on the right as you type.
  4. For HCL → JSON conversion, choose your preferred JSON indentation (2 or 4 spaces) from the options bar.
  5. Switch between Code and Tree view to explore the parsed JSON structure interactively.
  6. Click Copy or press Ctrl+Shift+C to copy the output to your clipboard.
  7. Use the Swap button to reverse the direction and move the current output into the input for round-trip conversions.

Popular HCL ↔ JSON Examples

View all HCL ↔ JSON examples →

FAQ

What is HCL and where is it used?

HCL (HashiCorp Configuration Language) is a structured configuration language created by HashiCorp. It is the primary configuration syntax for Terraform (infrastructure as code), Packer (machine images), Vault (secrets management), Consul (service mesh), Nomad (workload orchestration), and Waypoint (application deployment). HCL is designed to be human-readable while being machine-parseable, sitting between JSON and a full programming language.

What HCL constructs are supported?

The parser supports all major HCL block types: resource, variable, output, data, locals, module, provider, and terraform blocks. It handles attributes with strings, numbers, booleans, lists, maps, nested blocks, string interpolation expressions (${...}), heredoc strings (<<-EOT), comments (# and //), and function call syntax.

Why would I convert HCL to JSON?

Terraform supports JSON as an alternative configuration syntax (.tf.json files). JSON format is useful for programmatic generation of Terraform configurations, CI/CD pipeline integrations, code generation tools, and any scenario where you need to manipulate Terraform configs with standard JSON tooling. Some teams also use JSON when generating Terraform configurations from other programming languages.

Does the JSON to HCL conversion produce valid Terraform?

The converter generates syntactically correct HCL that follows Terraform conventions. Known block types (resource, variable, output, etc.) are reconstructed with proper block syntax. However, semantic validation (e.g., checking if resource types exist or attribute names are valid) is not performed. Always validate the generated HCL with terraform validate before applying.

How are Terraform expressions handled?

String interpolation expressions like ${var.name} and references like var.region or local.tags are preserved as strings during conversion. Function calls are also captured as string values. The tool focuses on structural conversion rather than expression evaluation, so all expressions pass through as-is.

Is my data safe?

Yes. All parsing and conversion runs entirely in your browser using JavaScript. No data is sent to any server. Your Terraform configurations, including any sensitive values like API keys, database passwords, or infrastructure secrets, never leave your machine. You can verify this by checking the Network tab in your browser's developer tools.

What are the keyboard shortcuts?

Press Ctrl+Shift+C to copy the converted output to your clipboard. The conversion happens automatically as you type, so there is no separate convert action needed.

Related Tools