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 🙏

© 2025 – Pkg Stats / Ryan Hefner

json-ledger

v0.0.1

Published

A framework for

Downloads

137

Readme

json-ledger

json-ledger is a lightweight JavaScript/TypeScript package designed to efficiently apply a series of changes to JSON objects and arrays. It provides utility functions to update, delete, or modify JSON data structures in a non-mutating and type-safe way.

Features

  • Immutable by default: The original JSON object or array is never mutated. Changes are applied to a deep clone of the input.
  • Path-based updates: Supports dot-separated string paths or arrays of strings for deeply nested properties.
  • Deletion support: Delete properties or array elements by specifying their path.
  • Type safety: Fully typed in TypeScript for safer and more predictable usage.
  • Compatibility: Built on top of es-toolkit for compatibility and utility functions.

Installation

npm install json-ledger

Usage

Basic Example

import { applyChanges } from 'json-ledger';

const initialJson = {
  user: {
    name: 'Alice',
    address: {
      city: 'Wonderland',
      zip: '12345',
    },
  },
};

const changes = [
  { path: 'user.name', value: 'Bob' },
  { path: 'user.address.zip', value: '54321' },
  { path: 'user.phone', value: '123-456-7890' },
  { path: 'user.address.city', value: undefined }, // Deletes the city property
];

const updatedJson = applyChanges(initialJson, changes);

console.log(updatedJson);

Output:

{
  "user": {
    "name": "Bob",
    "address": {
      "zip": "54321"
    },
    "phone": "123-456-7890"
  }
}

Advanced Example: Working with Arrays

const initialJson = {
  items: [
    { id: 1, name: 'Item 1' },
    { id: 2, name: 'Item 2' },
    { id: 3, name: 'Item 3' },
  ],
};

const changes = [
  { path: 'items.1.name', value: 'Updated Item 2' }, // Update the second item
  { path: 'items.2', value: undefined }, // Delete the third item
];

const updatedJson = applyChanges(initialJson, changes);

console.log(updatedJson);

Output:

{
  "items": [
    { "id": 1, "name": "Item 1" },
    { "id": 2, "name": "Updated Item 2" }
  ]
}

API

applyChanges

Parameters:

  • initialJson (JSONArray | JSONObject): The JSON object or array to apply changes to.
  • changes (ReadonlyArray<Change | ReadonlyArray<Change>>): One or more changes to apply.

Returns:

  • A new JSON object or array with the applied changes.

Change Type

A Change object has the following structure:

type Change = {
  path: Path; // Path to the property or array element to modify
  value: JSONValue | undefined; // New value to set, or undefined to delete the property/element
};

Path

  • A Path can be either:
    • A dot-separated string (e.g., 'user.address.city')
    • An array of strings (e.g., ['user', 'address', 'city'])

JSONValue

A JSONValue can be any of the following:

  • string
  • number
  • boolean
  • null
  • JSONObject
  • JSONArray

Utility Functions

set

Sets a value at a specified path within a JSON object or array.

get

Retrieves a value from a specified path within a JSON object or array.

has

Checks if a property or element exists at a specified path.

deletePropertyPath

Deletes a property or element at a specified path within a JSON object or array.

Contributing

Contributions are welcome! Please follow the standard GitHub flow:

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

License

This project is licensed under the MIT License. See the LICENSE file for details.