Terraform .tfvars ⇄ JSON Converter
Convert Terraform .tfvars variable files to JSON and back. Best for simple key = value files; complex HCL may need Terraform itself.
About this tool
This tool converts a Terraform .tfvars variable file into JSON, and JSON back into .tfvars. It handles the flat case: quoted strings, numbers, booleans, and inline lists or objects written as valid JSON, with hash and double-slash comment lines skipped.
The reason to convert is that Terraform accepts both formats. A .tfvars.json file is what you want when variables are generated by a pipeline or merged from a JSON source, because emitting HCL from a script is error-prone while emitting JSON is not. Converting the other way gives you a readable file to commit. Parsing runs in your browser and nothing you paste is transmitted, but as a matter of discipline do not paste real credentials into any web tool — variable files are exactly where credentials tend to live.
How to use it
Paste one format and select the button for the direction you want.
- tfvars to JSON reads key = value lines and emits a JSON object to save as terraform.tfvars.json.
- JSON to tfvars emits key = value lines from a flat JSON object.
- Keep the input flat. Multi-line HCL blocks, heredocs, interpolations and function calls are not parsed.
- Quote string values in the .tfvars input, otherwise they may be coerced to another type.
- Reviewing a change next? Use the Terraform plan summarizer.
Common questions
Will Terraform read the JSON output directly?
Yes, provided the file is named with a .tfvars.json suffix or passed explicitly with -var-file. Terraform's JSON variant of HCL expects a top-level object mapping variable names to values, which is what this tool produces.
Why did my complex tfvars file not convert?
The converter handles single-line key = value assignments. Nested blocks, multi-line maps, heredoc strings and expressions such as variable references or function calls need the real HCL parser. Use terraform console or a jq-based pipeline for those.
Is it safe to paste a tfvars file here?
The conversion runs entirely in your browser with no network calls, so the content stays on your machine. Even so, treat pasting secrets into any web page as something to avoid: strip passwords, tokens and keys first and keep them in a secrets manager.
