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

fat-json

v0.0.38

Published

Stringify and parse non-standard JSON [data types](#from-wikipedia): _reviver_ and _replacer_ functions for the built-in `JSON` object

Downloads

65

Readme

Fat Json

Stringify and parse non-standard JSON data types: reviver and replacer functions for the built-in JSON object

Install

npm i fat-json

Serialising and de-serialising

Transforming standard data types using the built-in JSON object is simple, but the JavaScript language now features other types like BigInt which don't serialise/cannot be coerced to another type without potential data loss

Serialising and de-serialising with JSON.stringify() and JSON.parse() provides some opportunity to safely transform data from one type to another with replacer and reviver functions

A typical replacer function for BigInt

We can test the value and transform based on its type

function replacer (key, value) {
  if (typeof value === 'bigint') return String(value)

  return value
}

It's hard to argue with the simplicity of transforming from a BigInt to a String but it's harder to see how we should transform back from a String to a BigInt without some additional information

A typical reviver function

Should we transform every String?

function reviver (key, value) {
  if (typeof value === 'string') return BigInt(value)

  return value
}

We could use a catch block. Or else format the key or value such that we can test one or both of them, and then decide what to do

Fat Json's third argument

Fat Json supplies a JSONPath as the third argument to your replacer or reviver function so you can decide whether to transform a value by its position in the JSON document, not just by its key or value. If you know the structure of your data in advance you can serialise and de-serialise safely and in one step

import {
  useReplacerWithPath,
  useReviverWithPath
} from 'fat-json'

const d = {
  id: BigInt(Number.MAX_SAFE_INTEGER)
}

const s = JSON.stringify(d, useReplacerWithPath((key, value, path) => {
  if (path === '$.id') return String(value)

  return value
}))

const o = JSON.parse(s, useReviverWithPath((key, value, path) => {
  if (path === '$.id') return BigInt(value)

  return value
}))

Any data which can be represented as a String can be serialised and de-serialised in the same way

From Wikipedia

JSON's basic data types are:

  • Number: a signed decimal number that may contain a fractional part and may use exponential E notation but cannot include non-numbers such as NaN. The format makes no distinction between integer and floating-point. JavaScript uses IEEE-754 double-precision floating-point format for all its numeric values (later also supporting BigInt), but other languages implementing JSON may encode numbers differently.
  • String: a sequence of zero or more Unicode characters. Strings are delimited with double quotation marks and support a backslash escaping syntax.
  • Boolean: either of the values true or false
  • Array: an ordered list of zero or more elements, each of which may be of any type. Arrays use square bracket notation with comma-separated elements.
  • Object: a collection of name–value pairs where the names (also called keys) are strings. The current ECMA standard states, "The JSON syntax does not impose any restrictions on the strings used as names, does not require that name strings be unique, and does not assign any significance to the ordering of name/value pairs." Objects are delimited with curly brackets and use commas to separate each pair, while within each pair, the colon ":" character separates the key or name from its value.
  • null: an empty value, using the word null