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

@ublitzjs/niche-json-stringify

v2.0.0

Published

A blazing-fast, preoptimising stringifier generator, designed to outpace `JSON.stringify` in Web on both frontend and backend, while being type-safe and still handling all character escaping.

Readme

@ublitzjs/niche-json-stringify - fastest pre-optimised niche JSON.stringify alternative

A blazing-fast, preoptimising stringifier generator, designed to outpace JSON.stringify in Web on both frontend and backend, while being type-safe and still handling all character escaping.

Inspired by fast-json-stringify and compile-json-stringify. As in compile-json-stringify, niche-json-stringify uses JSONSchema to define the input type, unlike fast-json-stringify. However, it handles only the most popular cases, that's why it is "niche".

μBlitz.js

Features

  • No Dependencies: Works in NodeJS, Bun and a Web browser
  • The fastest for small payloads: "niche" approach helped achieve these results. See benchmarks
  • Comparable speed with JSON.stringify for large payloads: in NodeJS for non-escaped strings and in Bun for both
  • TypeScript-first
  • Prebuilt for ESM and CJS
  • Thoroughly tested

Benchmarks

Installation

bun add @ublitzjs/niche-json-stringify

Quick start

Generate a specialized serializer from a JSON Schema (or a TypeBox schema). The generated function does not validate its input - it assumes the data already matches the schema.

import { Type } from "@sinclair/typebox";
import { createStringify } from "@ublitzjs/niche-json-stringify";

const User = Type.Object({
  id: Type.Integer(),
  name: Type.String(),
  admin: Type.Optional(Type.Boolean({ default: false })),
  tags: Type.Array(Type.String(), { default: [] }),
});

const stringify = createStringify(User);

const json = stringify({
  id: 1,
  name: "Alice",
});

console.log(json);
// {"id":1,"name":"Alice","admin":false,"tags":[]}

Default values

Schemas may define a default value for any supported type. If the corresponding property is undefined, the generated serializer emits the default instead.

const Config = Type.Object({
  host: Type.String({ default: "localhost" }),
  port: Type.Integer({ default: 3000 }),
  tls: Type.Boolean({ default: false }),
  retries: Type.Integer({ default: 3 }),
});

const stringify = createStringify(Config);

stringify({});
// {"host":"localhost","port":3000,"tls":false,"retries":3}

Unsafe strings

By default, all string values are JSON-escaped.

If you know a string is already safe (contains no characters requiring escaping), mark it with format: "unsafe" to skip escaping.

const LogEntry = Type.Object({
  timestamp: Type.String({ format: "unsafe" }),
  level: Type.String({ format: "unsafe" }),
  message: Type.String(), // escaped
});

const stringify = createStringify(LogEntry);

Additional properties

additionalProperties is supported. Unknown properties are serialized using JSON.stringify. However, it does not work with default values or with and outer object - only properties.

const Payload = Type.Object({
  id: Type.Integer(),
  extra: Type.Object({}, { additionalProperties: true }) 
});

const stringify = createStringify(Payload);

stringify({
  id: 1,
  extra: { hello: "world" },
});
// {"id":1,"extra":{"hello":"world"}}

Custom string escaping

By default, createStringify() uses the escaping implementation from fast-json-stringify.

You can supply another escaping function, for example the one from compile-json-stringify:

import {
  createStringify,
  CJSescape,
} from "@ublitzjs/niche-json-stringify";

const stringify = createStringify(User, CJSescape);

Specialized array serializers

For hot paths, the package also exports highly optimized serializers for common array types. Internally they are used when array has certain size and replaced with JSON.stringify when fed a huge one.

import {
  num_arr_node,
  num_arr_bun,
  bool_arr_bun,
  bool_arr_node,
  str_arr_node,
  str_arr_bun,
} from "@ublitzjs/niche-json-stringify";

int_arr_node([1, 2, 3]);
int_arr_bun([1, 2, 3]);
// "[1,2,3]"

// look for use cases
bool_arr_node([true, false]);
bool_arr_bun([true, false]);
// "[true,false]"

// optimised non-escaping serialisers
str_arr_node(["a", "b"]);
str_arr_bun(["a", "b"]);
// "[\"a\",\"b\"]"

Note: Generated serializers prioritize speed over safety. They do not validate input, so invalid data may produce invalid JSON or incorrect output. Validate your data before serialization if necessary.