Convert JSON to pretty jsonencode()
HCL calls for Terraform or OpenTofu
Try it online: json-to-pretty-jsonencode.baraniecki.eu
Or use the CLI via npx
:
# Convert JSON from the clipboard to HCL (Linux)
$ xsel -b | npx json-to-pretty-hcl -
jsonencode(...)
# Convert JSON from the clipboard to HCL (macOS)
$ pbpaste | npx json-to-pretty-hcl -
jsonencode(...)
# Convert a JSON file to HCL
$ cat package.json
{
"name": "json-to-pretty-hcl",
"version": "0.0.2",
"description": "Convert JSON to pretty OpenTofu/Terraform jsonencode() calls",
"main": "index.mjs",
"bin": {
"json-to-pretty-hcl": "./index.mjs"
},
"engines": {
"node" : ">=13.0.0"
},
"scripts": {
"cloudflare-pages-build": "mkdir -p website-dist && cp -rv index.html modules vendor website-dist/",
"test": "echo \"Error: no test specified\" && exit 1"
},
"exports": {
"./*": "./modules/*.mjs"
},
"repository": "github:karolba/json-to-pretty-hcl",
"keywords": [
"json",
"jsonencode",
"terraform",
"tofu",
"pretty"
],
"author": {
"name": "Karol Baraniecki",
"url": "https://baraniecki.eu"
},
"license": "AGPL-3.0-or-later",
"bugs": {
"url": "https://github.com/karolba/json-to-pretty-hcl/issues"
},
"homepage": "https://json-to-pretty-jsonencode.baraniecki.eu/",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
$ npx json-to-pretty-hcl package.json
jsonencode({
name = "json-to-pretty-hcl"
version = "0.0.2"
description = "Convert JSON to pretty OpenTofu/Terraform jsonencode() calls"
main = "index.mjs"
bin = {
"json-to-pretty-hcl" = "./index.mjs"
}
engines = {
node = ">=13.0.0"
}
scripts = {
"cloudflare-pages-build" = "mkdir -p website-dist && cp -rv index.html modules vendor website-dist/"
test = "echo \"Error: no test specified\" && exit 1"
}
exports = {
"./*" = "./modules/*.mjs"
}
repository = "github:karolba/json-to-pretty-hcl"
keywords = [
"json",
"jsonencode",
"terraform",
"tofu",
"pretty"
]
author = {
name = "Karol Baraniecki"
url = "https://baraniecki.eu"
}
license = "AGPL-3.0-or-later"
bugs = {
url = "https://github.com/karolba/json-to-pretty-hcl/issues"
}
homepage = "https://json-to-pretty-jsonencode.baraniecki.eu/"
publishConfig = {
access = "public"
registry = "https://registry.npmjs.org/"
}
})