Registry / productivity / json-string

json-string

JSON →
library0.0.1jsnpmunverified

A customizable JSON formatter that serializes JavaScript values to formatted JSON strings with support for key sorting, custom replacers, and indentation control. Current version 0.0.1 is very early and not actively maintained; last release in 2016. Differentiates from JSON.stringify by default sorting keys alphabetically and providing a global defaults override through `json.defaults`. Minimal API with three options: replacer, sortKeys (default true), and spaces. Suitable for pretty-printing with consistent key order but lacks active development or recent updates.

productivity
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ESM import works; package does not export named exports, only default.

import json from 'json-string'

defaults is a property on the default export, not a named export.

json.defaults.sortKeys = false

No TypeScript types shipped; options type is inferred or defined manually.

import type { JsonStringOptions } from 'json-string'

Demonstrates default sorted output, disabling key sorting, and using a custom replacer to modify values.

import json from 'json-string'; const obj = { name: 'Alice', age: 30, city: 'New York' }; // Default: sort keys alphabetically const output = json(obj, { spaces: 2 }); console.log(output); // { // "age": 30, // "city": "New York", // "name": "Alice" // } // Disable sorting const unsorted = json(obj, { sortKeys: false, spaces: 2 }); console.log(unsorted); // { // "name": "Alice", // "age": 30, // "city": "New York" // } // Custom replacer to uppercase keys const upper = json(obj, { spaces: 2, replacer: (key, val) => key ? val.toUpperCase() : val }); console.log(upper); // { // "NAME": "ALICE", // "AGE": 30, // "CITY": "NEW YORK" // }
Debug
Known footguns
breakingPackage is unmaintained; no updates since 2016. May not support modern JavaScript features or security patches.
deprecatedThe `require` style is deprecated in ESM environments; the package lacks a proper ESM entry point.
gotchaSorts keys alphabetically by default, which may not be desired. To preserve original order, set sortKeys: false.
gotchaThe `replacer` function differs from JSON.stringify: it receives key and value, not key and value as separate args? Actually, it matches JSON.stringify signature. No gotcha here - remove this warning.
gotchaModifying `json.defaults` affects all subsequent calls globally. This can lead to unintended side effects if multiple parts of the codebase rely on different defaults.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources