npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bhuvanshah/cjson

v0.1.4

Published

Compact JSON - Token-efficient serialization for LLMs

Readme

Compact JSON (CJSON)

Compact JSON (CJSON) is a token-efficient, human-readable serialization format inspired by TOON and optimized for LLM interactions. This repository contains the production-ready parser, encoder, and tooling along with the reference documentation.

Features

  • 40–70% token reduction compared to JSON
  • Familiar key/value syntax with optional compact array headers
  • Inline, multi-line, and compact array formats
  • Built-in comment support (# comment)
  • Zero runtime dependencies, written in TypeScript
  • Encode/decode/parsing APIs with rich error reporting

Installation

npm install @bhuvanshah/cjson
# or
yarn add @bhuvanshah/cjson

Note
If you're working from this repository before it's published to npm, run npm install in the repo root and import from ./src in your local experiments instead of '@bhuvanshah/cjson'.

Quick Start

import { encode, decode } from '@bhuvanshah/cjson';

const data = {
  name: 'Alice',
  age: 30,
  tags: ['developer', 'designer'],
  projects: [
    { name: 'Atlas', status: 'active' },
    { name: 'Zephyr', status: 'paused' },
  ],
};

const cjson = encode(data);
// name: Alice
// age: 30
// tags: [developer, designer]
// projects[2]{name, status}:
//   name: Atlas, status: active
//   name: Zephyr, status: paused

const parsed = decode(cjson);
// => original JavaScript object

Parsing only

import { parse, astToValue } from '@bhuvanshah/cjson';

const ast = parse('user:\n  name: Mira\n  active: true');
const value = astToValue(ast); // { user: { name: 'Mira', active: true } }

See docs/API.md for the full API surface (encode/decode/parse/options/validator).

CLI

After installing, use the cjson command to encode, decode, format, or validate from the shell:

cjson encode -f data.json          # JSON file → CJSON (stdout)
echo '{"name":"Alice"}' | cjson encode
echo 'name: Alice' | cjson decode   # CJSON (stdin) → JSON (stdout)
cjson format -f doc.cjson           # Normalize CJSON formatting
cjson validate -f doc.cjson         # Exit 0 if valid, 1 and errors to stderr
cjson --help
cjson --version

Input is from stdin by default, or from a file with -f / --file.

Important: encode expects JSON input. decode expects CJSON input (the key: value format). Do not run decode -f something.json on a JSON file—you’ll get bad output. Use a .cjson file or the output of encode for decode.

Try it with the sample or your own file

From the repo, run the CLI with node bin/cjson.js (after npm run build). If you installed the package (e.g. npm i -g @bhuvanshah/cjson or npx cjson), use cjson directly.

Encode (JSON → CJSON). Use a JSON file:

node bin/cjson.js encode -f examples/sample.json
# Or: cjson encode -f examples/sample.json
# Or any JSON file:
node bin/cjson.js encode -f path/to/your/data.json

Decode (CJSON → JSON). Use a CJSON file (we include examples/sample.cjson so you can try decode without creating one):

node bin/cjson.js decode -f examples/sample.cjson
# Or: cjson decode -f examples/sample.cjson

Round-trip (encode then decode):

node bin/cjson.js encode -f examples/sample.json | node bin/cjson.js decode
# Or with your own file:
node bin/cjson.js encode -f yourfile.json > out.cjson
node bin/cjson.js decode -f out.cjson

Syntax at a Glance

# Comments start with '#'
name: Alice
age: 30
tags: [js, ts, rust]

address:
  city: Seattle
  zip: 98101

users[2]{name, role}:
  name: Ada, role: admin
  name: Bob, role: user

More examples and formal rules are in docs/SPEC.md.

Documentation

Examples

Example scripts and a sample JSON file live in the examples/ directory:

  • examples/sample.json – sample JSON for encode (e.g. node bin/cjson.js encode -f examples/sample.json)
  • examples/sample.cjson – sample CJSON for decode (e.g. node bin/cjson.js decode -f examples/sample.cjson)
  • examples/basic.ts – encode/decode round trip
  • examples/parser.ts – inspect AST output
  • examples/validator.ts – validate documents against a schema
  • examples/arrays.ts – compact vs multi-line vs inline array encoding
  • examples/llm-integration.ts – encode prompt, mock LLM response, decode (pattern for APIs/agents)

Run them with tsx:

npx tsx examples/basic.ts
npx tsx examples/arrays.ts
npx tsx examples/llm-integration.ts

Development

npm install
npm run build        # compile TypeScript
npm test             # run unit & integration tests (Vitest)
npm run lint         # run ESLint on src
npm run benchmark    # measure encode/decode performance

CI is provided via GitHub Actions (.github/workflows/ci.yml) and runs lint + tests + build on pushes/PRs targeting main or phase-5.

Project Status

  • Current version: 0.1.3 (early release; API may evolve).
  • Parser, encoder, decoder, validator, CLI, and benchmarks are implemented and covered by tests.
  • Install from npm: npm install @bhuvanshah/cjson

Releasing (version bump and publish)

  1. Push all changes to GitHub (e.g. git push origin main).

  2. After push is complete, bump the version and publish to npm:

    npm version patch
    npm publish --access public
  3. Push the new version tag: git push origin main --follow-tags (or push the tag created by npm version patch).

License

MIT © 2025-present CJSON contributors.

Support / Issues

  • File bugs or questions here: https://github.com/Bhuvannnn/CJSON/issues
  • Install from npm: npm install @bhuvanshah/cjson

References