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

@lp-labs/react-json-patch

v0.1.0

Published

Safe RFC 6902 JSON Patch validation, application, preview, and React view.

Readme

@lp-labs/react-json-patch

An immutable-input JSON Patch validator, applier, previewer, and small controlled React preview for the supported RFC 6902 operations.

Example

import { applyPatch, JsonPatchEditor, type PatchOperation } from "@lp-labs/react-json-patch";
import "@lp-labs/react-json-patch/styles.css";

const patch: PatchOperation[] = [
  { op: "test", path: "/profile/name", value: "Grace" },
  { op: "replace", path: "/profile/name", value: "Ada" },
  { op: "add", path: "/tags/-", value: "verified" },
];
const result = applyPatch({ profile: { name: "Grace" }, tags: [] }, patch);
function Preview() { return <JsonPatchEditor document={{ profile: { name: "Grace" }, tags: [] }} patch={patch} />; }

React API

JsonPatchEditorProps is {document: unknown; patch: readonly unknown[]; onPatch?: (patch: readonly unknown[]) => void; className?: string}. JsonPatchEditor defaults its class to lp-json-patch; it previews the transformed JSON and error text in an aria-live output. The optional button calls onPatch with a shallow copy of the validated input operations; it does not mutate or replace the supplied document. It is disabled without a callback or if preview fails.

Helpers and types

  • PatchOperation is the union of RFC-shaped add, remove, replace, move, copy, and test operations. Add/replace/test carry value; move/copy carry from. Values are arbitrary cloneable JSON-compatible values.
  • JsonPatchError extends Error; operationIndex?: number identifies the operation that failed (validation or application).
  • decodePointer(pointer: string): string[] and encodePointer(parts: readonly string[]): string decode/encode RFC 6901 escaping (~1 slash, ~0 tilde). Invalid pointer structure or escapes throw JsonPatchError. Unsafe segments __proto__, prototype, and constructor are rejected on decode.
  • validatePatch(patch: readonly unknown[]): PatchOperation[] validates operation names, required properties, path and from pointers. Returns the original validated operation references and throws JsonPatchError with an index on invalid input.
  • PatchResult is {document: unknown; changed: boolean; operationIndex?: number}. applyPatch<T>(document: T, patch: readonly unknown[]): PatchResult clones the document, then applies operations in order without mutating input. test uses structural equality. Array indices must be canonical nonnegative decimal integers; add permits index equal to length and - for append. Object add creates/replaces a key; remove/replace require an existing key. Root add/replace are supported; root removal is not. Move into a descendant is rejected. Errors throw JsonPatchError with the operation index.
  • previewPatch(document: unknown, patch: readonly unknown[]): PatchResult is an alias in behavior for applyPatch.
  • JsonPatchEditorProps is the component props type.

Standards subset and limits

Implements the RFC 6902 operation set and RFC 6901 pointer escaping, with deliberately stricter prototype-related path rejection. It does not handle non-JSON values, custom equality, streaming/large documents, JSON text parsing, conflict resolution, or partial results: any failed operation throws and leaves the original document unchanged. structuredClone must be supported by the runtime. The preview component does not offer a JSON editing surface; callers supply patch data. Output is an accessible live region but does not implement a line-oriented diff. React is the only runtime peer; declarations accompany ESM/CJS builds.

License

MIT.

Support

If this library is useful to you, consider supporting its maintenance with a donation via PayPal.

Author

Created by Libin Prasanth. Connect on LinkedIn for updates and discussion.