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

@jithinaji/json-engine

v1.0.2

Published

Lightweight JSON state engine with undo, redo, batching and path based listeners

Readme

JSON Engine

npm version

A lightweight JSON state manager with built‑in undo/redo, batch operations, and path‑based listeners.

The engine helps manage complex JSON structures safely by tracking mutations using the Command Pattern.
All state changes are reversible and observable.

📦 npm package:
https://www.npmjs.com/package/@jithinaji/json-engine


Live Playground

Try the engine in your browser:

👉 https://jithinaji.github.io/JSONHelper/

Installation

Install the package from npm:

npm install @jithinaji/json-engine

Then import it in your project:

import createJSONEngine from "@jithinaji/json-engine"

Features

  • Dot‑path based state updates (a.b.c)
  • Undo / Redo history
  • Batch operations (transaction-like updates)
  • Change listeners scoped by path
  • Immutable reads using structuredClone
  • Lightweight and dependency‑free

Creating an Engine

const engine = createJSONEngine({
  user: {
    name: "Aji"
  }
})

API Reference

getData()

Returns a deep clone of the entire JSON state.

const data = engine.getData()

get(path)

Returns a cloned value from the specified path.

engine.get("user.name")

Throws if the path does not exist.


has(path)

Checks if a path exists.

engine.has("user.name")

set(path, value)

Sets a value using dot‑notation paths.

engine.set("user.age", 25)

If intermediate objects do not exist they are created automatically.


deleteKey(path)

Deletes a key at a path.

engine.deleteKey("user.age")

Throws if the key does not exist.


update(path, updater)

Updates a value using a function.

engine.update("counter", v => v + 1)

replace(newState)

Replaces the entire JSON state.

engine.replace({
  count: 10
})

The previous state is stored in history so it can be undone.


log()

Pretty prints the current state.

engine.log()

Undo / Redo

undo()

Reverts the most recent change.

engine.undo()

redo()

Re‑applies the last undone change.

engine.redo()

clearHistory()

Clears both undo and redo history stacks.

engine.clearHistory()

Batch Operations

Groups multiple updates into a single history entry.

engine.batch(() => {
  engine.set("a", 1)
  engine.set("b", 2)
})

Calling undo() will revert both operations together.

If an error occurs during the batch, all changes are rolled back.


Change Listeners

Listen to All Changes

engine.onChange(change => {
  console.log(change)
})

Listen to a Specific Path

engine.onChange(change => {
  console.log("User changed:", change)
}, "user")

Remove a Listener

engine.offChange(listener, "user")

Change Object Format

Every mutation emits a change object.

{
  type: "add" | "update" | "delete" | "replace",
  path: "user.name",
  oldValue: previousValue,
  newValue: newValue
}

Example

const engine = createJSONEngine()

engine.set("a", 1)
engine.set("a", 2)

engine.undo() // a = 1
engine.redo() // a = 2

engine.batch(() => {
  engine.set("b", 3)
  engine.set("c", 4)
})

engine.undo() // removes b and c

Design Notes

The engine internally uses:

  • Command Pattern for reversible operations
  • Transaction batching
  • Path‑based change propagation

This allows predictable and reversible state transitions.


License

MIT