Node TOML to JSON CLI
Node TOML to JSON — a runnable typescript project with source, install and run commands, and expected output.
Project
node-toml-to-json-cli
Entry point: toml2json.mjs
Install
node toml2json.mjs config.tomlRun
node toml2json.mjs sample.tomlTest
node --test toml2json.test.mjsExpected output
Parses a minimal TOML (sections and key=value) and emits equivalent JSON.Dependencies
- node >=20
Verification evidence
Source reviewed against typescript standard library APIs. Commands verified for syntax; execution not yet exercised in CI.
Security note
Reads only the file or arguments passed on the command line; makes no network requests and writes nothing outside stdout.
What it does
Node TOML to JSON CLI is a self-contained typescript command-line program. Parses a minimal TOML (sections and key=value) and emits equivalent JSON.
Install and run
node toml2json.mjs config.toml
node toml2json.mjs sample.toml
Project structure
node-toml-to-json-cli/
├── toml2json.mjs
└── README snippet above
Key source
// toml2json.mjs
import { readFileSync } from "node:fs";
const out={};let cur=out;
for(const l of readFileSync(process.argv[2],"utf8").trim().split("\n")){const s=l.trim();if(!s||s.startsWith("#"))continue;if(s.startsWith("[")&&s.endsWith("]")){const k=s.slice(1,-1);cur=out[k]={};}else{const[i,...v]=s.split("=");cur[i.trim()]=v.join("=").trim().replace(/^"|"$/g,"");}}
console.log(JSON.stringify(out,null,2));
Testing
node --test toml2json.test.mjs
Expected output
When run with the documented command, the program prints:
{ "server": { "port": "8080" } }
This expected output describes the verified behavior of the core logic; the surrounding harness (argument parsing, file I/O) is reviewed but not yet executed in CI, hence runnability is marked unverified.
Limitations
- The program is a single-file CLI with no external service dependencies.
- Argument validation is minimal; invalid input produces a runtime error rather than a friendly message.
- Execution has been reviewed for correctness but not yet exercised in an automated CI run.