toon2
v0.1.0
Published
Convert JSON to TOON and TOON to JSON (browser + Node, no dependencies).
Maintainers
Readme
toonjs
Convert JSON to TOON and TOON to JSON. Works in both browsers and Node.js with zero dependencies.
Install
npm install toonjsUsage (ESM)
import { toToon, fromToon } from "toonjs";
const obj = { name: "Mia", age: 7, tags: ["fast", "brave"], meta: { ok: true } };
const toon = toToon(obj);
// {
// name = "Mia",
// age = 7,
// tags = [
// "fast",
// "brave"
// ],
// meta = {
// ok = true
// }
// }
const back = fromToon(toon);Usage (CJS)
const { toToon, fromToon } = require("toonjs");TOON format (v0)
- Objects:
{ key = value, other = value } - Arrays:
[ value, value ] - Strings: double or single quoted with backslash escapes
- Numbers: JSON-style numbers
- Booleans:
true/false - Null:
null - Keys: bare identifiers (
[A-Za-z_][A-Za-z0-9_-]*) or quoted strings - Whitespace is ignored
- Trailing commas are allowed in arrays/objects
This format is intentionally small and deterministic to keep parsing and stringifying dependency-free.
API
toToon(value, options?)options.indent(default2, set to0for minified)options.quoteKeys(defaultfalse, force quoted keys)
fromToon(text)
License
MIT
