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

@happyvertical/json

v0.74.10

Published

High-performance JSON parsing and serialization with Rust SIMD acceleration and automatic fallback

Readme

@happyvertical/json

High-performance JSON parsing and serialization with Rust SIMD acceleration and automatic fallback.

Features

  • Drop-in replacements for JSON.parse() and JSON.stringify()
  • 2-3x faster parsing with SIMD acceleration on supported platforms
  • Automatic fallback to native JavaScript when Rust bindings unavailable
  • Deep clone function optimized for the JSON.parse(JSON.stringify()) pattern
  • Safe variants that don't throw on errors
  • TypeScript first with full type definitions

Installation

npm install @happyvertical/json
# or
pnpm add @happyvertical/json

Quick Start

import { parse, stringify, clone } from '@happyvertical/json';

// Drop-in replacements for JSON.parse/stringify
const data = parse<User>('{"name": "Alice", "age": 30}');
const json = stringify(data);

// Deep clone (optimized)
const copy = clone(data);
copy.age = 31; // Original unchanged

API

Drop-in Replacements

// Parse JSON string to value
function parse<T = unknown>(text: string, reviver?: Reviver): T;

// Stringify value to JSON
function stringify(value: unknown, replacer?: Replacer, space?: number | string): string;

// Deep clone via JSON round-trip (optimized)
function clone<T>(value: T): T;

Safe Variants (Non-throwing)

import { safeParse, safeStringify } from '@happyvertical/json';

// Returns { success: true, value: T } or { success: false, error: ParseError }
const result = safeParse<User>(maybeInvalidJson);
if (result.success) {
  console.log(result.value.name);
} else {
  console.error(`Line ${result.error.line}: ${result.error.message}`);
}

// Returns { success: true, value: string } or { success: false, error: StringifyError }
const stringifyResult = safeStringify(data);

Validation

import { isValid } from '@happyvertical/json';

if (isValid(userInput)) {
  const data = parse(userInput);
}

Adapter Control

import { JSONFactory, getAdapterInfo, isSIMDAvailable } from '@happyvertical/json';

// Check if SIMD acceleration is available
console.log(isSIMDAvailable()); // true on supported platforms

// Get detailed adapter info
const info = getAdapterInfo();
console.log(info.name);        // 'sonic' or 'native'
console.log(info.simdEnabled); // true if using SIMD

// Create adapter with specific options
const json = JSONFactory.create({
  adapter: 'sonic',    // 'sonic' | 'native' | 'auto'
  fallback: true,      // Fall back to native if sonic unavailable
});

// Use adapter directly
const data = json.parse('{"key": "value"}');
const text = json.stringify(data);

Performance

On a 680KB manifest file (typical SMRT manifest):

| Operation | Native JSON | @happyvertical/json | Speedup | |-----------|-------------|---------------------|---------| | Parse | ~50ms | ~18ms | 2.8x | | Stringify | ~45ms | ~16ms | 2.8x | | Clone | ~95ms | ~34ms | 2.8x |

Results measured on Apple M2 Pro. Performance varies by platform and data structure.

Platform Support

SIMD-accelerated parsing is available on:

  • ✅ macOS ARM64 (Apple Silicon)
  • ✅ macOS x64 (Intel)
  • ✅ Linux x64 (GNU)
  • ✅ Linux ARM64 (GNU)
  • ✅ Linux x64 (musl)
  • ✅ Linux ARM64 (musl)
  • ✅ Windows x64

When the native binary isn't available, the package automatically falls back to JavaScript's built-in JSON object with zero overhead.

How It Works

This package uses sonic-rs - a Rust JSON library that uses SIMD instructions (AVX2, SSE4.2, NEON) for vectorized parsing and serialization.

The adapter pattern allows:

  1. Automatic selection of the fastest available implementation
  2. Graceful fallback when native bindings can't be loaded
  3. Consistent API regardless of the underlying implementation

TypeScript Support

Full TypeScript definitions included:

interface User {
  name: string;
  age: number;
}

// Type-safe parsing
const user = parse<User>('{"name": "Alice", "age": 30}');
user.name; // string
user.age;  // number

// Safe variant preserves types
const result = safeParse<User>(json);
if (result.success) {
  result.value.name; // string
}

Reviver and Replacer

Standard reviver and replacer functions work as expected:

// Reviver for custom transformations
const data = parse<{ date: Date }>(
  '{"date": "2024-01-15"}',
  (key, value) => (key === 'date' ? new Date(value) : value)
);
console.log(data.date instanceof Date); // true

// Replacer for filtering
const json = stringify(data, ['name', 'email']); // Only include these keys

// Pretty printing
const pretty = stringify(data, null, 2);

Environment Variables

  • HAPPYVERTICAL_JSON_ADAPTER: Force adapter selection ('sonic' | 'native')

License

MIT