JSON to HCL Converter

Convert between JSON and HashiCorp Configuration Language (HCL) for Terraform configurations. Bidirectional conversion with instant results.

What is JSON to HCL Converter?

HCL (HashiCorp Configuration Language) is a human-readable configuration language designed for infrastructure as code, used by Terraform, Vault, Consul, Nomad, and other HashiCorp tools. HCL combines the readability of YAML with the structure of JSON, adding support for comments, variable interpolation, and conditional expressions. This converter transforms JSON data into HCL syntax and vice versa, making it easy to work with Terraform configurations in either format. Nested objects become HCL map blocks, arrays become list values, and primitive types are preserved with proper HCL quoting rules.

How to Use

  1. Select the conversion direction using the toggle button (JSON to HCL or HCL to JSON)
  2. Paste your JSON or HCL content into the input area
  3. Click "Convert" to generate the output in the target format
  4. Review the output — complex HCL features like resource blocks may need manual adjustment
  5. Copy the result and use it in your Terraform project or configuration pipeline

Why Use This Tool?

Convert Terraform JSON configurations (.tf.json) to readable HCL (.tf) format for easier maintenance
Transform API responses or JSON data into Terraform variable definitions and locals blocks
Migrate CloudFormation JSON templates or other JSON-based IaC to Terraform HCL syntax
Quickly prototype HCL configurations from existing JSON data structures
Bidirectional conversion lets you switch between JSON and HCL formats as needed
Proper handling of HCL quoting, nested maps, and array syntax in both directions

Tips & Best Practices

  • Terraform supports both .tf (HCL) and .tf.json (JSON) files natively — use whichever format fits your workflow
  • HCL supports comments (// and #) which JSON does not — comments are lost when converting HCL to JSON
  • Complex HCL features like resource blocks with labels, dynamic blocks, for_each, and locals may require manual adjustment after conversion
  • When converting from JSON to HCL, nested objects become HCL map blocks with key = value syntax
  • Use the JSON format for machine-generated Terraform configs and HCL for human-written ones

Frequently Asked Questions

What is HCL and how does it differ from JSON?

HCL (HashiCorp Configuration Language) is a configuration language built by HashiCorp that is designed to be both human-readable and machine-friendly. Unlike JSON, HCL supports comments (// and #), does not require quotes around keys, uses = instead of :, and allows for more expressive syntax like variable interpolation, conditional expressions, and for expressions. It is the standard format for Terraform infrastructure definitions.

Can Terraform use JSON instead of HCL?

Yes. Terraform supports JSON configuration files with the .tf.json extension alongside .tf HCL files. While HCL is recommended for human-written configs, JSON works well for machine-generated configurations. Terraform processes both formats identically, so you can mix .tf and .tf.json files in the same directory.

When should I NOT use this converter?

Avoid this converter for HCL files that use advanced features like resource blocks with multiple labels, dynamic blocks, template directives, provider configurations, or complex expressions with variables and functions. The converter handles key-value pairs and nested structures well, but Terraform-specific constructs like resource "aws_instance" "web" { ... } require manual authoring.

Why convert JSON to HCL?

HCL is more readable and supports comments, making it easier for teams to review and maintain. Converting JSON to HCL is useful when you have machine-generated configs (e.g., from Terraform Cloud exports or CDKTF) that you want to edit by hand. It also helps when migrating from JSON-based tools like CloudFormation to Terraform.

How are nested objects handled in the conversion?

When converting JSON to HCL, nested objects become HCL map blocks with proper indentation. For example, {"tags": {"env": "production"}} becomes tags = { env = "production" }. When converting HCL to JSON, map blocks are parsed back into nested JSON objects with the same structure.

Is my data sent to a server?

No. All conversion happens entirely in your browser using client-side JavaScript. Your Terraform configurations and JSON data never leave your device, making this tool safe for use with infrastructure definitions that may contain sensitive resource names or network configurations.

Real-world Examples

Terraform Variable Definitions from JSON

Convert a JSON config object to HCL format for use as Terraform variable defaults or locals.

Input
{"resource_group": "myapp-prod", "location": "eastus", "enabled": true, "tags": {"env": "production", "team": "platform"}, "replicas": 3}
Output
resource_group = "myapp-prod"
location = "eastus"
enabled = true

tags = {
  env = "production"
  team = "platform"
}

replicas = 3

HCL to JSON for API Processing

Convert HCL configuration to JSON format for processing by automation tools or CI/CD pipelines.

Input
region = "us-west-2"
instance_type = "t3.medium"

tags = {
  Name = "web-server"
  Environment = "staging"
}
Output
{
  "region": "us-west-2",
  "instance_type": "t3.medium",
  "tags": {
    "Name": "web-server",
    "Environment": "staging"
  }
}

Related Tools