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

llm-json-compact

v1.0.0

Published

Compact JSON into a table-like structure that removes repeated keys and is easier for LLMs to consume with fewer tokens.

Readme

llm-json-compact

Compact JSON into a table-like structure that removes repeated keys and is easier for LLMs to consume with fewer tokens.

Instead of repeating field names on every object, llm-json-compact lifts shared keys into a header row and keeps only the values in each row.

Why

Raw JSON is verbose for LLM input, especially for arrays of objects.

[
  { "name": "John", "age": 30, "city": "New York" },
  { "name": "Jane", "city": "Boston" }
]

With llm-json-compact:

[["name","age","city"],["John",30,"New York"],["Jane",,"Boston"]]

Install

npm install llm-json-compact

Quick Start

import { jsonCompact, stringifyCompact } from "llm-json-compact";

const compacted = jsonCompact([
  { name: "John", age: 30, city: "New York" },
  { name: "Jane", city: "Boston" },
]);

console.log(compacted);
// [
//   ["name", "age", "city"],
//   ["John", 30, "New York"],
//   ["Jane", undefined, "Boston"]
// ]

console.log(stringifyCompact(compacted));
// [["name","age","city"],["John",30,"New York"],["Jane",,"Boston"]]

API

jsonCompact(input)

Compacts a plain object or an array of plain objects into a nested array structure.

stringifyCompact(compacted)

Serializes compacted output into a shorter string form for LLM prompts.

Rules:

  • Middle undefined values are rendered as empty slots: ["Jane",,"Boston"]
  • Trailing undefined values are omitted
  • null stays null

Output Rules

  • A plain object becomes a two-row table: headers + values
  • An array of objects becomes one header row plus one row per object
  • A nested object becomes a single compact column like address[city,zip]
  • An array of objects inside a field becomes a compact column like addresses[city,street]
  • Scalar arrays are kept as-is
  • New keys discovered in later rows are appended to the header row

Examples

Plain object

jsonCompact({
  name: "John",
  age: 30,
  city: "New York",
});

// [
//   ["name", "age", "city"],
//   ["John", 30, "New York"]
// ]

Nested object

jsonCompact({
  name: "John",
  age: 30,
  address: {
    city: "New York",
    zip: "10001",
  },
});

// [
//   ["name", "age", "address[city,zip]"],
//   ["John", 30, ["New York", "10001"]]
// ]

Array of objects

jsonCompact([
  { name: "John", age: 30, hobbies: ["reading", "traveling"] },
  { name: "Jane", age: 25, hobbies: ["cooking"], city: "New York" },
]);

// [
//   ["name", "age", "hobbies", "city"],
//   ["John", 30, ["reading", "traveling"]],
//   ["Jane", 25, ["cooking"], "New York"]
// ]

Nested array of objects

jsonCompact({
  name: "John",
  age: 30,
  addresses: [
    { city: "New York", street: "1225 Hanover Street" },
    { city: "Los Angeles", street: "456 Sunset Boulevard" },
  ],
});

// [
//   ["name", "age", "addresses[city,street]"],
//   [
//     "John",
//     30,
//     [
//       ["New York", "1225 Hanover Street"],
//       ["Los Angeles", "456 Sunset Boulevard"]
//     ]
//   ]
// ]

Limitations

  • Input must be a plain object or an array of plain objects
  • Empty arrays are inferred with a small heuristic, so field naming can affect whether an empty array is treated as scalar or object-like
  • The format is intentionally compact, not strict JSON schema
  • This is optimized for LLM consumption, not lossless typed serialization

Development

npm test
npm run build