https://github.com/lugondev/format-json-llm
Convert JSON ↔ TOON and generate JSON Schema + compact TOON schema for LLM prompts. Token-efficient, with live token comparison.
https://github.com/lugondev/format-json-llm
converter json json-schema llm prompt-engineering schema-generator token-optimization toon vanilla-js vite
Last synced: about 21 hours ago
JSON representation
Convert JSON ↔ TOON and generate JSON Schema + compact TOON schema for LLM prompts. Token-efficient, with live token comparison.
- Host: GitHub
- URL: https://github.com/lugondev/format-json-llm
- Owner: lugondev
- Created: 2026-06-07T03:49:00.000Z (4 days ago)
- Default Branch: main
- Last Pushed: 2026-06-07T04:43:04.000Z (4 days ago)
- Last Synced: 2026-06-07T06:20:54.463Z (4 days ago)
- Topics: converter, json, json-schema, llm, prompt-engineering, schema-generator, token-optimization, toon, vanilla-js, vite
- Language: JavaScript
- Homepage: https://lugondev.github.io/format-json-llm/
- Size: 50.8 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# format-json-llm
A small JS module + web UI to convert between **JSON** and **TOON**
([Token-Oriented Object Notation](https://toonformat.dev)) and to generate
**schemas** (standard JSON Schema + a compact TOON schema) you can paste into an
LLM prompt so the model understands your request/response format.
TOON is a compact, token-efficient encoding of JSON designed for LLM prompts —
fewer tokens than JSON for the same data, especially for arrays of objects.
## Features
- **Bidirectional convert:** JSON → TOON and TOON → JSON.
- **Schema generation:**
- JSON Schema (draft 2020-12) inferred from a sample value.
- Compact TOON schema, e.g. `users:[]{id:int,name:str}`.
- **Token comparison:** JSON vs TOON token counts and the percentage saved
(via `gpt-tokenizer`).
- **Live UI:** two-panel editor, debounced realtime conversion, delimiter /
indent / strict / keyFolding options, swap source, copy output, and friendly
error messages.
## Getting started
```bash
npm install
npm run dev # start the Vite dev server
npm run build # production build into dist/
npm test # run the Vitest suite
```
## Project structure
```
src/
core/ # pure logic, zero DOM (unit-tested)
toon.js # jsonToToon / toonToJson (wraps @toon-format/toon)
schema-json.js # toJsonSchema -> JSON Schema 2020-12
schema-toon.js # toToonSchema -> compact type signature
tokens.js # countTokens / compareTokens
index.js # aggregated core API
ui/ # DOM + events
panels.js # builds the shell, output/error/token setters
controls.js # reads encode/decode options, debounce, clipboard
app.js # wiring + render loop
main.js # entry point
tests/ # Vitest (core unit tests + jsdom UI integration tests)
```
## Core API
```js
import {
jsonToToon, toonToJson,
toJsonSchema, toToonSchema,
countTokens, compareTokens,
} from './src/core/index.js';
jsonToToon(jsonString, opts) // -> { ok, toon, error }
toonToJson(toonString, opts) // -> { ok, json, value, error }
toJsonSchema(value) // -> JSON Schema object (draft 2020-12)
toToonSchema(value) // -> compact signature string
compareTokens(jsonText, toon) // -> { jsonTokens, toonTokens, savedPercent }
```
Encode/decode options are passed straight through to
[`@toon-format/toon`](https://www.npmjs.com/package/@toon-format/toon)
(`delimiter`, `indent`, `keyFolding`, `strict`, `expandPaths`).
## License
MIT