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

@yarmu/json-repair

v1.0.2

Published

TypeScript implementation of json-repair - Fix invalid JSON strings

Readme

JSON Repair - TypeScript Implementation

A complete TypeScript port of the popular json-repair Python library.

This library can fix invalid JSON strings, which is especially useful when dealing with LLM outputs that may have malformed JSON.

✅ 100% Feature Parity | ✅ Fully Type-Safe | ✅ Production Ready

Features

  • Fix missing quotes, brackets, and commas
  • Handle incomplete arrays and objects
  • Auto-complete missing values
  • Remove comments from JSON
  • Support for streaming/incomplete JSON
  • Strict mode for validation

Installation

npm install @yarmu/json-repair

Usage

import { repairJson, loads } from '@yarmu/json-repair';

// Repair and return as string
const fixed = repairJson('{"name": "John", "age": 30');
console.log(fixed); // '{"name": "John", "age": 30}'

// Repair and parse to object
const obj = loads('{"name": "John", "age": 30');
console.log(obj); // { name: 'John', age: 30 }

API

repairJson(jsonStr, options?)

Repairs a JSON string and returns the fixed JSON string or parsed object.

Parameters:

  • jsonStr (string): The JSON string to repair
  • options (object, optional):
    • returnObjects (boolean): If true, return parsed object instead of string. Default: false
    • skipJsonParse (boolean): Skip initial JSON.parse validation. Default: false
    • logging (boolean): Return repair log along with result. Default: false
    • streamStable (boolean): Keep repairs stable for streaming JSON. Default: false
    • strict (boolean): Raise errors instead of repairing certain issues. Default: false

Returns: string | JSONReturnType | [JSONReturnType, RepairLog[]]

loads(jsonStr, options?)

Works like JSON.parse() but repairs the JSON first.

Parameters:

  • jsonStr (string): The JSON string to parse
  • options (object, optional):
    • skipJsonParse (boolean): Skip initial JSON.parse validation. Default: false
    • logging (boolean): Return repair log along with result. Default: false
    • streamStable (boolean): Keep repairs stable for streaming JSON. Default: false
    • strict (boolean): Raise errors instead of repairing. Default: false

Returns: JSONReturnType | [JSONReturnType, RepairLog[]]

load(fd, options?)

Read and repair JSON from a file descriptor.

Parameters:

  • fd (number): File descriptor
  • options (object, optional): Same as loads

Returns: JSONReturnType | [JSONReturnType, RepairLog[]]

fromFile(filename, options?)

Read and repair JSON from a file.

Parameters:

  • filename (string): Path to JSON file
  • options (object, optional): Same as loads

Returns: JSONReturnType | [JSONReturnType, RepairLog[]]

Examples

import { repairJson, loads } from '@yarmu/json-repair';

// Missing closing brace
repairJson('{"name": "John"'); // '{"name": "John"}'

// Missing quotes
repairJson('{name: "John"}'); // '{"name": "John"}'

// Trailing comma
repairJson('{"name": "John",}'); // '{"name": "John"}'

// With comments
repairJson('{"name": "John" /* comment */}'); // '{"name": "John"}'

// Direct parsing
const obj = loads('{"name": "John", "age": 30');
// Returns: { name: 'John', age: 30 }

// With logging
const [result, log] = repairJson('{"name": "John"', {
  returnObjects: true,
  logging: true
});
console.log(log); // Array of repair operations

// Strict mode (throws on structural issues)
try {
  repairJson('{"key": "value", "key": "duplicate"}', { strict: true });
} catch (e) {
  console.error('Duplicate keys found!');
}

License

MIT

Credits

This is a TypeScript port of the Python json-repair library by Stefano Baccianella.