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

congeal

v0.1.0

Published

Best-effort parse of an incomplete/streaming JSON prefix — closes open strings, arrays, and objects so you get a usable value at every step. Never throws on truncation.

Readme

congeal

npm MIT License

Best-effort parse of an incomplete/streaming JSON prefix — closes open strings, arrays, and objects so you get a usable value at every step. Never throws on truncation.

The problem

When streaming JSON from APIs or LLMs, you receive partial chunks truncated mid-string, mid-object, or mid-array. Standard JSON.parse() throws on incomplete input, forcing you to buffer and wait. congeal solves this by intelligently closing open structures to produce usable values at every step, enabling progressive parsing without buffering.

Install

npm install congeal
# or
pnpm add congeal
# or
yarn add congeal

Use

import congeal, { isComplete } from "congeal";

// Parse incomplete JSON without throwing
const partial = '{"name":"Alice","age":30,"cit';
const result = congeal(partial); // { name: 'Alice', age: 30 }
isComplete(partial); // false
// LLM tool-call streaming scenario
const chunks = [
  '{"function_name":"get_w',
  '{"function_name":"get_weather","param',
  '{"function_name":"get_weather","parameters":{"location":"NYC"}}',
];

chunks.forEach(chunk => {
  const parsed = congeal(chunk);
  console.log(parsed);
  // Progressive results: { function_name: 'get_w' }, { function_name: 'get_weather' }, ...
});
// Control partial string behavior
congeal('{"msg":"Hello', { partialStrings: true });  // { msg: 'Hello' }
congeal('{"msg":"Hello', { partialStrings: false }); // {}

API

congeal(input, options?)

Best-effort parse of an incomplete/streaming JSON prefix.

Parameters:

  • input (string): The JSON prefix to parse
  • options? (CongealOptions): Optional configuration
    • partialStrings? (boolean): Include partial string content (default: true)

Returns: T | undefined — The parsed value, or undefined if nothing parseable

Behavior: Closes open strings, arrays, and objects to produce valid JSON. Drops incomplete tokens (keywords, numbers, dangling separators). Never throws — returns undefined for unparseable input. Handles escape sequences correctly.

isComplete(input)

Check if the input is already complete, valid JSON.

Parameters:

  • input (string): The JSON string to check

Returns: boolean — True if input is valid JSON, false otherwise

Behavior: Uses JSON.parse() internally. Returns false for incomplete or invalid JSON. Throws are caught and converted to false return.

CongealOptions

Options for controlling congeal behavior.

Properties:

  • partialStrings? (boolean): When true (default), keeps partial string content. When false, drops open strings entirely.

Non-goals

JSON schema validation: Does not validate types or schemas. Use zod or ajv for validation.

const result = congeal('{"age":"thirty"}'); // { age: 'thirty' } - no type checking

Malformed JSON fixing: Only handles truncation, not malformed JSON like trailing commas.

congeal('{"name": "Alice", }'); // undefined - can't fix trailing comma

Cross-chunk state: Each call is independent — no buffering or state across calls.

congeal('{"name": "Alice", "ag'); // { name: 'Alice' }
congeal('e": 30}');               // undefined - no cross-chunk memory

Non-standard JSON: Does not handle comments, trailing commas, or unquoted keys.

TypeScript

import congeal, { isComplete } from "congeal";

// Type parameter for result
const result: Record<string, unknown> | undefined = congeal(input);

// With known structure
interface User { name: string; age: number; }
const user: User | undefined = congeal<User>('{"name":"Alice","age":30}');

Related Packages

License

MIT