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-morph

v1.0.1

Published

Transform JSON like a boss.

Downloads

24

Readme

🦎 json-morph NPM version NPM downloads

Transform JSON like a boss.
Filter it. Reshape it. Clean it. Remix it. All from your terminal.

"Why mutate your JSON by hand when you can morph it like a shapeshifter?"


✨ What is json-morph?

json-morph is a command-line tool and API that helps you transform JSON data using simple, expressive flags.

  • 🧠 Filter using logical expressions (age > 18 && status == 'active')
  • 🔁 Map keys to new paths (user.namefullName)
  • ➕ Add static fields (role:admin)
  • ❌ Remove sensitive fields (password, secret)
  • 💅 Pretty-print or export to a new file

Perfect for quick one-liners, data munging, CLI pipelines, config transforms, and replacing brittle jq scripts for common tasks.


🚀 Installation

npm install -g json-morph

🛠️ Usage

json-morph input.json [options]

Options

| Flag | Description | | --- | --- | | --map | Remap keys: "from.path:to.path" | | --filter | Filter expression: "age > 18 && active == true" | | --add | Add static fields: "key:value" | | --remove | Remove fields: "password,token" | | --preserve | Preserve all original fields (used with --map) | | --output, -o | Output to a file | | --pretty | Pretty-print output | | --help | Show help | | --version | Show version |

🔍 Examples

🧼 Filter and Clean

npx json-morph users.json \
  --filter "age > 21 && active == true" \
  --remove "password,internalNote" \
  --output active-users.json

🔄 Remap Keys

npx json-morph input.json \
  --map "user.name:fullName" \
  --map "user.id:userId" \
  --preserve

➕ Add Fields

npx json-morph input.json \
  --add "status:active" \
  --add "score:100"

🧪 Combine It All

npx  json-morph data.json \
  --filter "score >= 80" \
  --map "user.email:contact.email" \
  --add "passed:true" \
  --remove "debugLog" \
  --pretty

🧬 Programmatic Usage

You can also use json-morph as a library:

import { transformJson } from 'json-morph';

const data = [{ name: 'Alice', age: 25 }];
const flags = {
  filter: ['age > 18'],
  map: ['name:fullName'],
  add: ['status:active'],
};

const output = transformJson(data, flags);
console.log(output);

⚡ Why Use json-morph?

  • ✅ Lightweight, dependency-free
  • ✅ Safer and easier than writing ad hoc scripts
  • ✅ Works with deeply nested JSON
  • ✅ Expressive filter logic without learning jq
  • ✅ Scriptable, composable, and fun ✨

👤 About the Author

Built by cinfinit, a part-time JSON whisperer, full-time logic artisan, and lifelong member of the "why-is-this-API-like-this" club. Loves:

  • Clean abstractions
  • Messy data
  • Terminal one-liners that look like sorcery When not mutating JSON structures, probably found arguing with a linter, renaming variables obsessively, or building another side project that absolutely no one asked for — but everyone secretly needed. “If it involves curly braces and chaos, I’m probably interested.”