{"id":16093,"library":"js-hcl-parser","title":"HCL Parser for JavaScript","description":"The `js-hcl-parser` package provides a fully functional JavaScript parser for HashiCorp Configuration Language (HCL), enabling seamless conversion between HCL syntax and JSON objects. Currently stable at version 1.0.1, its primary differentiator is its genesis: the JavaScript code is generated directly from the official HashiCorp HCL Go repository using `gopherjs`. This approach aims to ensure high fidelity and compatibility with the canonical HCL specification, making it a reliable choice for projects needing to interact with HCL configurations in a JavaScript environment. The library offers both parsing HCL strings into JSON and stringifying JSON back into HCL, catering to diverse configuration management needs. Release cadence is not explicitly stated but typically follows updates or major changes in the upstream HCL Go library.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/vgsantoniazzi/js-hcl-parser","tags":["javascript","hcl","json","parser","js"],"install":[{"cmd":"npm install js-hcl-parser","lang":"bash","label":"npm"},{"cmd":"yarn add js-hcl-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add js-hcl-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The README examples use CommonJS `require`, but ESM `import` is the recommended modern approach for this default export.","wrong":"const HCL = require('js-hcl-parser')","symbol":"HCL","correct":"import HCL from 'js-hcl-parser'"},{"note":"The `parse` function is a method of the default-exported `HCL` object, not a named export from the package root.","wrong":"import { parse } from 'js-hcl-parser'","symbol":"HCL.parse","correct":"import HCL from 'js-hcl-parser';\nconst parsed = HCL.parse(hclString);"},{"note":"The `stringify` function is a method of the default-exported `HCL` object, not a named export from the package root.","wrong":"import { stringify } from 'js-hcl-parser'","symbol":"HCL.stringify","correct":"import HCL from 'js-hcl-parser';\nconst hclOutput = HCL.stringify(jsonObject);"}],"quickstart":{"code":"import HCL from 'js-hcl-parser';\n\n// Example HCL input string\nconst hclInput = `\nscale {\n  from = 72\n  to = 24\n}\n`;\n\n// Example JSON input object (or string representation)\nconst jsonInput = `\n{\n  \"scale\": {\n    \"from\": 72,\n    \"to\": 72\n  }\n}\n`;\n\n// Parse HCL to a JavaScript object\nconsole.log('Parsed HCL:', HCL.parse(hclInput));\n// Expected output: { scale: { from: 72, to: 24 } }\n\n// Stringify a JSON string to HCL format\n// Note: stringify expects a JSON string, not a JS object directly.\nconsole.log('Stringified JSON:', HCL.stringify(jsonInput));\n/* Expected output (formatting may vary slightly):\nscale {\n  from = 72\n  to = 72\n}\n*/","lang":"javascript","description":"Demonstrates how to parse an HCL string into a JavaScript object and how to stringify a JSON string back into HCL format."},"warnings":[],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[],"ecosystem":"npm"}