README · API Reference · Contributing
This directory contains real-world examples demonstrating how to use Jsonlet in production-like scenarios.
A fully typed, validating command-line Todo application. It demonstrates how to seamlessly combine Jsonlet's atomic persistence with Zod for strict schema validation.
- Type-safe State: Infers TypeScript types directly from the Zod schema.
- On-Load Validation: Rejects malformed or manually edited JSON files before they can crash your app.
- Transactional Updates: Uses
db.update()to mutate state safely. - Synchronous Reads: Uses
db.read()to fetch the deeply frozen, cached state. - Cross-process Safety: Try running multiple
addcommands simultaneously from different terminals—Jsonlet's file locks guarantee no data is lost!
From the repository root, install the development dependencies:
bun installThen use Bun to execute the CLI commands.
bun run examples/todo.ts add "Write documentation"
bun run examples/todo.ts add "Publish to npm"bun run examples/todo.ts listTake note of the short ID printed next to each task.
bun run examples/todo.ts complete <short-id>When you run this example, Jsonlet automatically creates a data/ directory in the root of your project and generates todo.json.
- Open
data/todo.jsonin your text editor. - Manually change a
"completed": falseboolean to a string:"completed": "not yet". - Run
bun run examples/todo.ts list. - Watch Jsonlet and Zod instantly intercept the corrupted state and throw a safe validation error, protecting your application from continuing with bad data!
The generated data/todo.json file is local example state and should not be committed.