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

@mightydatainc/json-surgery

v1.2.1

Published

An easy-to-call function that invokes iterative, AI-guided edits to a JSON-compatible object

Readme

@mightydatainc/json-surgery

Iterative, AI-guided JSON modification powered by LLM services. Pass in any JSON-compatible object and natural-language instructions. jsonSurgery breaks the task into discrete atomic operations (assign, delete, append, insert, rename, etc.) that are verified and applied methodically until the object satisfies your instructions.

Installation

npm install @mightydatainc/json-surgery

Quick Start

import OpenAI from 'openai';
import { jsonSurgery } from '@mightydatainc/json-surgery';

const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

const data = {
  title: 'My Report',
  items: [
    { id: 1, status: 'draft' },
    { id: 2, status: 'draft' },
  ],
};

const result = await jsonSurgery(
  client,
  data,
  'Set the status of every item to "published".'
);
console.log(result);

JSONSurgeryOptions

All options are optional.

| Option | Type | Description | | ------------------------ | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | | schemaDescription | string | Human-readable schema description passed to the model so it can stay within the expected structure. | | skippedKeys | string[] | Keys to omit from the placemarked JSON shown to the model (e.g. large blobs irrelevant to the task). | | onValidateBeforeReturn | (obj) => Promise<{ objCorrected?: any; errors?: string[] } \| undefined> | Called before the final object is returned. Return errors to force another round of corrections, or objCorrected to substitute a fixed version. | | onWorkInProgress | (obj) => Promise<any \| undefined> | Called at the start of each iteration after the first. Receives the current in-progress object; return a replacement to override it, or throw to abort. | | giveUpAfterSeconds | number | Throw JSONSurgeryError if the process exceeds this many seconds. | | giveUpAfterIterations | number | Throw JSONSurgeryError if the process exceeds this many iterations. |

import OpenAI from 'openai';
import { jsonSurgery, JSONSurgeryOptions } from '@mightydatainc/json-surgery';

const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

const options: JSONSurgeryOptions = {
  schemaDescription: "Object with a 'title' string and an 'items' array.",
  giveUpAfterSeconds: 120,
  giveUpAfterIterations: 20,
  onValidateBeforeReturn: async (obj) => {
    if (!obj.title) return { errors: ['title is required'] };
  },
};

const result = await jsonSurgery(
  client,
  data,
  "Remove the 'draft' items and capitalise the title.",
  options
);

JSONSurgeryError

Thrown when the process times out or exceeds the iteration limit. The partially-modified object is available on the exception as .obj.

import { jsonSurgery, JSONSurgeryError } from '@mightydatainc/json-surgery';

try {
  const result = await jsonSurgery(client, data, '...', {
    giveUpAfterIterations: 5,
  });
} catch (e) {
  if (e instanceof JSONSurgeryError) {
    console.error('Gave up:', e.message);
    console.log('Last known state:', e.obj);
  }
}

Utility exports

placemarkedJSONStringify

Serializes a JSON-compatible object to a string annotated with path comments, the same format shown to the model internally.

import { placemarkedJSONStringify } from '@mightydatainc/json-surgery';

console.log(placemarkedJSONStringify({ a: [1, 2] }, 2));
// // root
// {
//   // root["a"]
//   "a": [
//     // root["a"][0]
//     1,
//
//     // root["a"][1]
//     2
//   ]
// }

navigateToJSONPath

Traverses a JSON-compatible object by a path array and returns the parent, key/index, and target.

import { navigateToJSONPath } from '@mightydatainc/json-surgery';

const result = navigateToJSONPath({ items: [{ name: 'Alice' }] }, [
  'items',
  0,
  'name',
]);
console.log(result.pathTarget); // "Alice"

Installation and usage

npm install `@mightydatainc/json-surgery`
import { jsonSurgery } from '@mightydatainc/json-surgery';

Requires node >=24.0.