Terraform tfvars to JSON Converter
Convert a Terraform .tfvars file written in HCL into the equivalent .tfvars.json, or go the other way. Terraform accepts variable definitions in either form, and the JSON form is far easier to generate from a script or a pipeline. Strings, numbers, booleans, lists, and nested maps are all preserved. Conversion happens locally in your browser — nothing is uploaded.
How to use the Terraform tfvars to JSON Converter
Paste your variable file into the input box. With tfvars → JSON selected, the HCL assignments are parsed and re-emitted as a JSON object — the exact shape Terraform reads from a *.tfvars.json file. Switch to JSON → tfvars to turn a JSON object back into HCL assignments. The output regenerates as you type, and any parse error is shown below the box.
Pass the result to Terraform with terraform apply -var-file="prod.tfvars.json". The JSON form is useful when another program writes your variables — CI systems, templating tools, and the jsonencode function all produce JSON more naturally than HCL, and Terraform treats the two formats as equivalent.
tfvars and tfvars.json
A .tfvars file supplies values for the input variables a Terraform module declares. The default form is HCL: a flat list of name = value assignments, where the value can be a string, number, boolean, list, or map. Terraform automatically loads terraform.tfvars and any *.auto.tfvars, and you can point it at others with -var-file.
Terraform also accepts the same data as JSON when the file ends in .tfvars.json. The JSON object's keys are the variable names and its values are the variable values, using ordinary JSON types — objects for maps, arrays for lists. The two formats are interchangeable; Terraform decides how to parse a variables file purely from its extension.
The JSON form matters because machines write JSON more reliably than HCL. A CI job, a script, or another Terraform configuration using jsonencode can emit a valid .tfvars.json without implementing an HCL writer. This converter bridges the two: author values comfortably in HCL and get JSON for your pipeline, or take JSON another tool produced and read it as familiar HCL.
Common use cases
- Generating variables in CI. Produce
.tfvars.jsonfrom a script when an HCL writer would be awkward. - Reading machine-written variables. Convert a generated JSON variables file to HCL to review it by eye.
- Migrating configs. Move between the HCL and JSON variable formats without hand-editing.
- Learning HCL. See how each HCL value type maps onto its JSON equivalent.