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

@ahsankhanamu/json-transformer

v0.1.6

Published

JSON Query and Transformation Language

Readme

@ahsankhanamu/json-transformer

A lightweight JSON query and transformation language that compiles to JavaScript.

Installation

npm install @ahsankhanamu/json-transformer

Tree-Shaking & Subpath Imports

For smaller bundles, import only what you need:

// Full API (convenient)
import { evaluate, compile, toJS } from '@ahsankhanamu/json-transformer';

// Individual modules (tree-shakable)
import { parse, Parser } from '@ahsankhanamu/json-transformer/parser';
import { generate, NativeCodeGenerator } from '@ahsankhanamu/json-transformer/codegen';
import { helpers } from '@ahsankhanamu/json-transformer/runtime';
import * as AST from '@ahsankhanamu/json-transformer/ast';

Quick Examples

import { evaluate } from '@ahsankhanamu/json-transformer';

const data = {
  user: { name: 'John', age: 30 },
  orders: [
    { product: 'Widget', price: 25.99 },
    { product: 'Gadget', price: 49.99 }
  ]
};

// Property access
evaluate('user.name', data);                    // "John"

// Array operations
evaluate('orders[].product', data);             // ["Widget", "Gadget"]
evaluate('orders[? .price > 30]', data);        // Filter by price

// Transformations
evaluate('orders.map(x => x.price * 2)', data); // [51.98, 99.98]
evaluate('user.name | upper', data);            // "JOHN"

API

import { compile, evaluate, validate, toJS, parse } from '@ahsankhanamu/json-transformer';

// compile(expr, options?) - Returns reusable function (fastest for repeated use)
const fn = compile('user.name | upper');
fn({ user: { name: 'john' } }); // 'JOHN'

// evaluate(expr, data, options?) - One-shot evaluation with caching
evaluate('price * qty', { price: 10, qty: 5 }); // 50

// validate(expr) - Check syntax without executing
validate('user.name'); // null (valid)
validate('user.');     // ParseError

// toJS(expr, options?) - Generate JS source code
toJS('a + b'); // 'return (input?.a + input?.b);'

// parse(expr) - Get AST for inspection
parse('a.b'); // { type: 'Program', expression: { type: 'MemberAccess', ... } }

Options

interface Options {
  strict?: boolean;  // Throw errors vs return undefined (default: false)
  cache?: boolean;   // Cache compiled functions (default: true)
}

Syntax

Property Access

user.firstName              // Simple access
user.address.city           // Nested access
user?.middleName            // Optional chaining

Array Operations

orders[0]                   // First element
orders[-1]                  // Last element
orders[].product            // Property projection → ["Widget", "Gadget"]
orders[0:3]                 // Slice
orders[? .price > 20]       // Filter

Array Methods

orders.map(x => x.price)           // Map
orders.filter(x => x.price > 20)   // Filter
orders.find(x => x.id == 1)        // Find
orders[].sort(.price)              // Sort
orders[].groupBy(.category)        // Group

Pipe Operations

name | upper | trim                           // Chain functions
orders.find(x => x.id === 3) | .status        // jq-style property access
"hello" | .toUpperCase()                      // Method calls
user | { name: .firstName, city: .address.city }  // Object construction

Expressions

price * quantity + tax              // Arithmetic
firstName & " " & lastName          // String concatenation
`Hello ${user.name}!`               // Template literals
age >= 18 ? "Adult" : "Minor"       // Ternary
nickname ?? "Anonymous"             // Null coalescing

Object Construction

{ name: user.firstName, city: user.address.city }
{ ...user, fullName: firstName & " " & lastName }

Variable Bindings

let total = price * qty;
let tax = total * 0.1;
{ subtotal: total, tax, total: total + tax }

Built-in Functions

| Category | Functions | |----------|-----------| | String | upper, lower, trim, split, join, replace, substring, contains, capitalize, camelCase, snakeCase, kebabCase | | Math | round, floor, ceil, abs, min, max, clamp | | Array | sum, avg, count, first, last, unique, flatten, reverse, sort, groupBy, keyBy, take, drop | | Object | keys, values, entries, pick, omit, merge, get, set | | Type | type, isString, isNumber, isArray, isObject, isEmpty | | Conversion | toString, toNumber, toJSON, fromJSON |

Code Generation Modes

Forgiving Mode (default) - Returns undefined for missing paths:

toJS('user.address.city');
// → input?.user?.address?.city

Strict Mode - Throws descriptive errors:

toJS('user.address.city', { strict: true });
// Throws: "Property 'city' does not exist at path 'user.address'"

Links

License

MIT