Skip to main content

@winglet/json

@winglet/json npm versionlicense
yarn add @winglet/json

TypeScript library for safe JSON data manipulation. Implements RFC 6901 (JSON Pointer) and RFC 6902 (JSON Patch) with prototype pollution protection, immutable operations, and sub-path exports.

Installation

yarn add @winglet/json

Sub-path Exports

Import pathContents
@winglet/jsonAll exports
@winglet/json/pointerFull JSON Pointer API
@winglet/json/pointer-manipulatorgetValue, setValue, compilePointer
@winglet/json/pointer-patchJSON Patch operations
@winglet/json/pointer-escapeescapePath, unescapePath
@winglet/json/pathJSON Path constants

Key Exports

Pointer Manipulation (/pointer-manipulator)

  • getValue(object, pointer, options?) — read a value at a JSON Pointer path
  • setValue(object, pointer, value, options?) — write a value at the path
  • compilePointer(pointer) — compile a pointer to reusable segments

JSON Patch (/pointer-patch)

  • compare(a, b, options?) — generate RFC 6902 patch between two objects
  • applyPatch(object, patches, options?) — apply a patch array
  • difference(a, b) — generate RFC 7396 merge patch
  • mergePatch(object, patch) — apply a merge patch

Options

OptionDefaultDescription
immutabletrueReturn new object instead of mutating
protectPrototypetrueBlock __proto__, constructor, prototype
strictfalseThrow on missing paths

Usage Examples

import { getValue, setValue } from '@winglet/json/pointer-manipulator';

const data = { user: { name: 'Alice', roles: ['admin'] } };

getValue(data, '/user/name'); // 'Alice'
setValue(data, '/user/name', 'Bob'); // new object, original unchanged
import { compare, applyPatch } from '@winglet/json/pointer-patch';

const a = { x: 1, y: 2 };
const b = { x: 1, y: 3, z: 4 };

const patch = compare(a, b);
// [{ op: 'replace', path: '/y', value: 3 }, { op: 'add', path: '/z', value: 4 }]

applyPatch(a, patch); // { x: 1, y: 3, z: 4 }
AI Agent Reference

AI Reference

Package: @winglet/json v0.10.0 Purpose: RFC 6901 JSON Pointer and RFC 6902 JSON Patch with security protections.

Key exports

./path → JSONPath
./path-common → convertJsonPathToPointer
getJSONPath
./pointer → JSONPointer
./pointer-common → convertJsonPointerToPath
getJSONPointer
./pointer-escape → escapeSegment
escapePath
unescapePath
unescapeSegment
./pointer-manipulator → getValue
setValue
compilePointer
./pointer-patch → applyPatch
ApplyPatchOptions (type)
compare
CompareOptions (type)
difference
mergePatch
Patch (type)
TestPatch (type)
AddPatch (type)
ReplacePatch (type)
RemovePatch (type)
CopyPatch (type)
MovePatch (type)