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.

npm install json-string
INSTALL
IMPORT
SIG · JSON-STRING
J
json-string
productivityjavascriptv0.0.1
harness data pending
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.

json
import json from 'json-string'
const json = require('json-string')
ESM import works; package does not export named exports, only default.
defaults
json.defaults.sortKeys = false
import { defaults } from 'json-string'
defaults is a property on the default export, not a named export.
type
import type { JsonStringOptions } from 'json-string'
No TypeScript types shipped; options type is inferred or defined manually.

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 issues
breakingPackage is unmaintained; no updates since 2016. May not support modern JavaScript features or security patches.
fix
Consider using JSON.stringify with sorting implemented manually or use a maintained alternative like 'json-stable-stringify'.
affects: <=0.0.1
deprecatedThe `require` style is deprecated in ESM environments; the package lacks a proper ESM entry point.
fix
Use import json from 'json-string' in modern JS or transpile with bundler.
affects: >=0.0.0
gotchaSorts keys alphabetically by default, which may not be desired. To preserve original order, set sortKeys: false.
fix
Explicitly pass { sortKeys: false } if you want to keep insertion order.
affects: >=0.0.0
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.
affects: >=0.0.0
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.
fix
Use per-call options instead of modifying defaults, or clone defaults before modification.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: json is not a function
Using CommonJS require on an ESM-only build (if imported from a modern bundler) or incorrect import syntax.
fix
Use import json from 'json-string' or const json = require('json-string').default if using require and the package is transpiled.
Cannot find module 'json-string'
Package not installed or typo in package name.
fix
Run `npm install json-string` and ensure package.json contains it.
json.string is not a function (misleading error)
User mistakenly calls `json.string(obj)` instead of `json(obj)`.
fix
Call the default export directly: json(obj) or json(obj, options).
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
27 hits · last 30 days
node
24
OpenAI (training)
1
Resources
json-string — npm install json-string · libregistry