Categories

HCL-JSON Converter

Convert between HashiCorp Configuration Language (HCL) and JSON formats for Terraform configurations

Key Facts

Category
Format Conversion
Input Types
textarea, select, number
Output Type
text
Sample Coverage
4
API Ready
Yes

Overview

The HCL-JSON Converter is a specialized utility designed to seamlessly transform configuration files between HashiCorp Configuration Language (HCL) and JSON, ensuring compatibility for your Terraform infrastructure projects.

When to Use

  • When you need to integrate Terraform configurations with automated tools that only support JSON.
  • When migrating legacy JSON-based infrastructure definitions into standard HCL format.
  • When you need to validate or inspect complex HCL structures by viewing them in a machine-readable JSON format.

How It Works

  • Paste your HCL or JSON configuration code into the input area.
  • Select the desired conversion direction (HCL to JSON or JSON to HCL).
  • Adjust the JSON indent size if necessary to match your project's style guide.
  • Click the convert button to generate and copy your transformed configuration.

Use Cases

Standardizing infrastructure-as-code repositories by converting legacy JSON configs to HCL.
Generating dynamic Terraform variables using external scripts that output JSON.
Debugging complex HCL files by converting them to JSON to check for structural errors.

Examples

1. Converting HCL to JSON for API Integration

DevOps Engineer
Background
An automated CI/CD pipeline requires infrastructure parameters in JSON format to trigger a deployment API.
Problem
The existing infrastructure is defined in HCL, which the API cannot parse.
How to Use
Paste the HCL code into the input, select 'HCL to JSON', and set the indent size to 4.
Example Config
Direction: HCL to JSON, Indent: 4
Outcome
A clean, machine-readable JSON file ready for immediate use in the deployment pipeline.

2. Migrating JSON Configs to Terraform

Cloud Architect
Background
A legacy system uses JSON-based configuration files that need to be integrated into a new Terraform-managed environment.
Problem
Manually rewriting JSON to HCL is error-prone and time-consuming.
How to Use
Paste the JSON content, select 'JSON to HCL', and convert to generate the required HCL syntax.
Example Config
Direction: JSON to HCL
Outcome
Accurate HCL code that can be directly pasted into your main.tf file.

Try with Samples

json, image, text

Related Hubs

FAQ

Is this tool compatible with all Terraform versions?

Yes, the converter handles standard HCL and JSON syntax used across all major Terraform versions.

Can I convert multiple files at once?

This tool is designed for individual configuration blocks; please process files one at a time.

Does the tool store my configuration data?

No, all conversions are performed locally in your browser, and your data is not stored or transmitted.

What is the purpose of the JSON Indent Size option?

It allows you to control the readability of the output JSON by setting the number of spaces used for indentation.

Will comments in HCL be preserved in JSON?

JSON does not support comments; therefore, any comments present in your HCL input will be removed during the conversion to JSON.

API Documentation

Request Endpoint

POST /en/api/tools/hcl-json-converter

Request Parameters

Parameter Name Type Required Description
inputText textarea Yes -
conversionDirection select Yes -
jsonIndentSize number No -

Response Format

{
  "result": "Processed text content",
  "error": "Error message (optional)",
  "message": "Notification message (optional)",
  "metadata": {
    "key": "value"
  }
}
Text: Text

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-hcl-json-converter": {
      "name": "hcl-json-converter",
      "description": "Convert between HashiCorp Configuration Language (HCL) and JSON formats for Terraform configurations",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=hcl-json-converter",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]