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.

.tfvars.json output

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.json from 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.

Frequently asked questions

Does Terraform really accept JSON variables?

Yes. A file named with the .tfvars.json extension is parsed as JSON, and one ending in .tfvars is parsed as HCL. The two are equivalent; Terraform chooses the parser from the file extension, so either form supplies the same variable values.

Does this support all HCL expressions?

It converts literal values — strings, numbers, booleans, lists, and maps or objects, including nested ones. It does not evaluate HCL expressions, function calls, or variable interpolation, because a variables file is meant to hold concrete values rather than logic.

Are comments preserved?

No. JSON has no comment syntax, so HCL comments (# and //) are dropped when converting to JSON. When converting JSON back to HCL, the output is plain assignments without comments.

Is my data uploaded?

No. The entire conversion runs in JavaScript in your browser. Your variable values — which often include environment names, account IDs, and other sensitive details — never leave your device.

How are heredoc strings handled?

A heredoc (<