jsondecode.com logo

JSON to Terraform HCL Variables Converter — Free Online

Convert JSON to Terraform HCL variable blocks and locals definitions using AI. Maps JSON types to Terraform types automatically. Free, no sign-up required.

JSON to BigQuery Schema Converter — Free Online ToolJSON to React Flow Diagram — Convert JSON Online FreeJSON to Go Struct with BSON Tags — Free Online ToolJSON to TypeScript Interface Generator — Free OnlineJSON to YAML Converter — Convert JSON to YAML OnlineJSON to CSV Converter — Export JSON Array to CSV FreeJSON to Python Dataclass Generator — Free Online ToolJSON to SQL INSERT Statement Generator — Free OnlineJSON to Markdown Table Converter — Free Online ToolJSON to XML Converter — Convert JSON to XML Online FreeJSON to HTML Table Converter — Free Online ToolYAML to JSON Converter — Convert YAML to JSON Online FreeXML to JSON Converter — Convert XML to JSON Online FreeJSON to JSON Schema Generator — Free Online ToolJSON to GraphQL Schema Generator — Free Online ToolRuby to JSON Converter — Convert Ruby Hashes to JSON OnlineJSON to C# Class Generator — Free Online ToolJSON to Java Class (POJO) Generator — Free Online ToolJSON to Kotlin Data Class Generator — Free Online ToolJSON to Rust Struct Generator — Free Online ToolJSON to PHP Array Converter — Free Online ToolCSV to JSON Converter — Free Online ToolJSON to Dart Class Generator — Free Online ToolJSON to Swift Struct (Codable) Generator — Free OnlineJSON to Mongoose Schema Generator — Free Online ToolJSON to Prisma Schema Model Generator — Free OnlineJSON to Protocol Buffer (proto3) Generator — Free OnlineJSON to TOML Config Format Converter — Free Online ToolTOML to JSON Converter — Convert TOML to JSON Online FreeJSON to Apache Avro Schema Generator — Free Online ToolJSON to OpenAPI 3.0 Schema Component — Free Online ToolJSON to R Data Frame Code Generator — Free Online ToolJSON to Lua Table Syntax Converter — Free Online ToolJSON to Zod Schema (TypeScript) Generator — Free OnlineJSON to Scala Case Class with Circe Codec — Free OnlineJSON to PowerShell Hashtable Converter — Free Online Tool

JSON to Terraform HCL Variables Converter — Free Online

About JSON to Terraform HCL Variables Converter — Free Online

JSON to Terraform HCL converts JSON objects into Terraform variable declarations and locals blocks, mapping JSON types to their HCL equivalents so infrastructure configuration can be expressed as code. Developers use it to migrate existing JSON-based configs, API responses, or CloudFormation templates into Terraform-compatible HCL without manually rewriting every field.

JSON to HCL Type Mapping

JSON TypeHCL TypeExample InputExample Output
stringstring"region": "us-east-1"region = "us-east-1"
number (integer)number"port": 8080port = 8080
number (float)number"threshold": 0.75threshold = 0.75
booleanbool"enabled": trueenabled = true
nullnull"value": nullvalue = null
objectobject / map(any)"tags": {"env": "prod"}tags = { env = "prod" }
array of stringslist(string)"cidrs": ["10.0.0.0/8"]cidrs = ["10.0.0.0/8"]
array of objectslist(object(...))"rules": [{"port": 80}]rules = [{ port = 80 }]
nested objectobject(...) or any"network": {"vpc": {"id": "vpc-1"}}network = { vpc = { id = "vpc-1" } }

HCL Variable Block vs Locals Block

Attributevariable blocklocals block
PurposeAccepts input from caller (CLI, tfvars, env)Defines internal computed or static values
Syntaxvariable "name" { default = value }locals { name = value }
Override at runtimeYes — via -var, .tfvars, TF_VAR_*No — computed once during plan/apply
Type constraintOptional type = string/number/bool/list/mapNot supported; type is inferred
Validation blockSupported (condition + error_message)Not supported
Reference syntaxvar.namelocal.name
Best forEnvironment-specific values, secrets, togglesDerived values, tag maps, repeated expressions
Sensitive flagsensitive = true hides value in outputmark with sensitive() function

Frequently Asked Questions

How do I convert a JSON object to a Terraform locals block?

Wrap each top-level JSON key as an assignment inside a locals { } block and replace JSON colons with equals signs, remove double quotes from keys, and drop commas. For example, {"region": "us-east-1", "count": 3} becomes locals { region = "us-east-1" count = 3 }. Nested objects become inline HCL maps using curly braces, and arrays become HCL tuples using square brackets.

What is the difference between a Terraform variable and a local in HCL?

A variable block declares an input that callers supply at runtime via -var flags, .tfvars files, or TF_VAR_ environment variables, making it suitable for environment-specific values like region or instance type. A locals block defines values that are computed once during plan/apply and cannot be overridden externally, making it better for derived expressions, repeated tag maps, or intermediate calculations. Reference variables with var.name and locals with local.name.

Can I use JSON directly in Terraform instead of converting to HCL?

Yes. Terraform natively parses .tf.json files that use JSON syntax matching the HCL structure, so you can write your entire configuration in JSON. However, most teams prefer HCL for its readability, comments support, and string interpolation syntax. The jsondecode() built-in function also lets you parse a JSON string at runtime inside an expression, for example to read a JSON file with file() and decode it inline.

How does Terraform handle JSON null values when converted to HCL?

JSON null maps directly to the HCL literal null. When used as a variable default (default = null) it signals that the variable has no default and must be supplied, unless the type is marked optional. In a locals block or resource argument, null tells Terraform to omit the attribute, which causes the provider to use its own default for that field.

What Terraform HCL types do JSON arrays map to?

A JSON array maps to an HCL tuple when elements are mixed types, or to a typed list/set when all elements share the same type — for instance list(string) for an array of strings or list(object({...})) for an array of uniform objects. In variable type constraints you should specify the most specific type possible (list(string), set(number)) so Terraform can validate inputs at plan time. For locals, the type is inferred automatically from the assigned value.

If jsondecode.com saved you time, share it with your team

Free forever. No ads. No sign-up. Help other developers find it.