npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tfx2json

v1.0.0

Published

Convert Terraform / OpenTofu templates (.tf) to JSON for saner ops

Readme

tfx2json

Convert Terraform / OpenTofu templates (.tf) to JSON for saner ops. This project also supports decoding HCL expressions into a parseable JSON format.

This is currently done in two passes:

  • pass 1: parse the HCL into a general JSON structure using hcl2json WASM.
  • pass 2: expand expressions left by pass 1 into JSON with tree-sitter-hcl.

Usage

Library is published as a UMD module for NodeJS currently.

npm install tfx2json
const { tfx2json } = require('tfx2json');
const fs = require('fs');

const hcl = tfx2json(fs.readFileSync('sample.tf'));
console.log(JSON.stringify(hcl, null, 2));

Build

Go 1.22+ and TinyGO are required for building.

  • make sure git submodules are up to date, git, go and tinygo are in $PATH
  • run npm install
  • run npm run build
  • run npm run bundle
  • put something in sample.tf
  • run node -e 'var r=require;r("./dist").tfx2json(r("fs").readFileSync("sample.tf")).then(hcl=>console.log(JSON.stringify(hcl,null,2)))

given the following terraform template:

provider "aws" {
  region = "eu-west-1"
}

data "aws_availability_zones" "available" {}

locals {
  cluster_name = "jasonb-eks"
}

module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "2.66.0"

  name                 = "jasonb-vpc"
  cidr                 = "10.0.0.0/16"
  azs                  = data.aws_availability_zones.available.names
  public_subnets       = ["10.0.4.0/24", "10.0.5.0/24", "10.0.6.0/24"]
  enable_dns_hostnames = true
}


resource "aws_security_group" "external_connection" {
  name_prefix = "all_worker_management"
  vpc_id2      = module.vpc.vpc_id[*].0
  vpc_id      = module.vpc.vpc_id.*.0
  rando       = var.create_secondary_cluster ? 1 : 0

  ingress {
    from_port3 = -123
    from_port2 = 22 + 123
    from_port = 22
    to_port   = 22
    protocol  = "tcp"

    cidr_blocks = [
      "0.0.0.0/0",
    ]
  }
}

currently it outputs:

{
  "data": {
    "aws_availability_zones": {
      "available": [
        {}
      ]
    }
  },
  "locals": [
    {
      "cluster_name": "jasonb-eks"
    }
  ],
  "module": {
    "vpc": [
      {
        "azs": {
          "fn": "expression",
          "args": [
            {
              "name": "term",
              "value": {
                "fn": "identifier",
                "args": [
                  {
                    "name": "name",
                    "value": "data"
                  }
                ]
              }
            },
            {
              "name": "rest",
              "value": [
                "aws_availability_zones",
                "available",
                "names"
              ]
            }
          ]
        },
        "cidr": "10.0.0.0/16",
        "enable_dns_hostnames": true,
        "name": "jasonb-vpc",
        "public_subnets": [
          "10.0.4.0/24",
          "10.0.5.0/24",
          "10.0.6.0/24"
        ],
        "source": "terraform-aws-modules/vpc/aws",
        "version": "2.66.0"
      }
    ]
  },
  "provider": {
    "aws": [
      {
        "region": "eu-west-1"
      }
    ]
  },
  "resource": {
    "aws_security_group": {
      "external_connection": [
        {
          "ingress": [
            {
              "cidr_blocks": [
                "0.0.0.0/0"
              ],
              "from_port": 22,
              "from_port2": {
                "fn": "add",
                "args": [
                  {
                    "name": "lhs",
                    "value": 22
                  },
                  {
                    "name": "rhs",
                    "value": 123
                  }
                ]
              },
              "from_port3": -123,
              "protocol": "tcp",
              "to_port": 22
            }
          ],
          "name_prefix": "all_worker_management",
          "rando": {
            "fn": "conditional",
            "args": [
              {
                "name": "cond",
                "value": {
                  "fn": "expression",
                  "args": [
                    {
                      "name": "term",
                      "value": {
                        "fn": "identifier",
                        "args": [
                          {
                            "name": "name",
                            "value": "var"
                          }
                        ]
                      }
                    },
                    {
                      "name": "rest",
                      "value": [
                        "create_secondary_cluster"
                      ]
                    }
                  ]
                }
              },
              {
                "name": "true",
                "value": 1
              },
              {
                "name": "false",
                "value": 0
              }
            ]
          },
          "vpc_id": {
            "fn": "expression",
            "args": [
              {
                "name": "term",
                "value": {
                  "fn": "identifier",
                  "args": [
                    {
                      "name": "name",
                      "value": "module"
                    }
                  ]
                }
              },
              {
                "name": "rest",
                "value": [
                  "vpc",
                  "vpc_id",
                  "*",
                  0
                ]
              }
            ]
          },
          "vpc_id2": {
            "fn": "expression",
            "args": [
              {
                "name": "term",
                "value": {
                  "fn": "identifier",
                  "args": [
                    {
                      "name": "name",
                      "value": "module"
                    }
                  ]
                }
              },
              {
                "name": "rest",
                "value": [
                  "vpc",
                  "vpc_id",
                  "*",
                  0
                ]
              }
            ]
          }
        }
      ]
    }
  }
}