llm-json-lite
v0.0.9
Published
A tiny utility to convert JavaScript objects into a relaxed JSON format optimized for LLM prompts.
Maintainers
Readme
llm-json-lite
A tiny utility to convert JavaScript objects into a relaxed JSON format optimized for LLM (Large Language Model) prompts.
Instead of strict JSON with quotes and colons, llm-json-lite outputs a compact format using = for assignment and minimal noise — perfect for reducing token usage in LLM inputs.
💡 Save 8–16% tokens on average compared to standard JSON — meaning cheaper, faster, and more efficient LLM calls.
Features
- Compact format – saves tokens when sending data to LLMs.
- 8–16% fewer tokens – lower cost and faster processing.
- Human-readable – no quotes, no colons.
- Smart filtering – removes
null,undefined, and empty arrays. - Date handling – serializes
Dateobjects to ISOYYYY-MM-DD.
Installation
pnpm add llm-json-lite
# or
npm install llm-json-lite
# or
yarn add llm-json-liteUsage
import { optimize } from "llm-json-lite"
const data = {
name: "Alice",
age: 25,
active: true,
tags: ["dev", "ai"],
birthday: new Date("2000-01-01"),
empty: [],
optional: null
}
console.log(optimize(data))Output
You are given RELAXED-JSON where keys use = instead of : for assignment and items are comma-separated.
Rules:
- Objects: {k=v,k=v,...}
- Arrays: [v,v,...]
- Strings are unquoted and contain no spaces. Booleans are true/false. Dates are ISO (YYYY-MM-DD).
- Null/undefined/empty arrays are omitted.
DATA_START
{name=Alice,age=25,active=true,tags=[dev,ai],birthday=2000-01-01}
DATA_ENDAPI
optimize(obj: Record<string, any>): string
Converts a JS object into a string that includes the instructions and the relaxed JSON data.
Use Cases
Preparing data for LLM prompts (ChatGPT, Claude, etc.)
Token-efficient serialization
Easy-to-read logs and debugging
Contributing
PRs are welcome! If you have suggestions or improvements, open an issue or submit a PR.
License
MIT © Pavel Surinin
