jsonrail
v1.0.0
Published
JSON pointers, RFC 6902 patches, structural diffs, and deep merge for Node.js
Maintainers
Readme
jsonrail
JSON tools for Node.js: pointers (RFC 6901), patches (RFC 6902), structural diffs, and deep merge.
Zero runtime dependencies. Node 18+.
Install
npm install jsonrailQuick start
import { get, set, diff, applyPatch, merge, pointerFromPath } from "jsonrail";
const doc = { user: { name: "Ada", tags: ["math"] } };
get(doc, "/user/name"); // "Ada"
get(doc, pointerFromPath("user.tags[0]")); // "math"
const next = set(doc, "/user/age", 36);
const patch = diff(doc, next);
// [{ op: "add", path: "/user/age", value: 36 }]
applyPatch(doc, patch);
merge({ a: { x: 1 } }, { a: { y: 2 }, b: 3 });
// { a: { x: 1, y: 2 }, b: 3 }Patch operations
add, remove, replace, move, copy, test.
applyPatch({ items: ["a"] }, [
{ op: "add", path: "/items/-", value: "b" },
{ op: "test", path: "/items/1", value: "b" },
]);get, set, and remove do not mutate the original document.
License
MIT
