# JavaScript JSON libraries

JavaScript JSON libraries parse and serialize JSON beyond what the built-in JSON.parse and JSON.stringify handle. Each one extends that pair in one direction, such as comments in configuration files, sorted keys for stable hashes, or circular references. These libraries read the configuration files, cache keys, and logged objects that apps and developer tools exchange as JSON.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [JSON5](#json) | 1.2B | 7.2K | Dec 2022 | MIT |
| [fast-json-stable-stringify](#fast-json-stable-stringify) | 811.8M | Not on GitHub | Dec 2019 | MIT |
| [flatted](#flatted) | 797.9M | 1.2K | Jul 2026 | ISC |
| [parse-json](#parse-json) | 727.1M | Not on GitHub | Apr 2025 | MIT |
| [json-stable-stringify-without-jsonify](#json-stable-stringify-without-jsonify) | 700.0M | Not on GitHub | Dec 2016 | MIT |
| [@ungap/structured-clone](#ungap-structured-clone) | 493.6M | Not on GitHub | Aug 2026 | ISC |
| [jsonc-parser](#jsonc-parser) | 414.0M | Not on GitHub | Jun 2024 | MIT |
| [safe-stable-stringify](#safe-stable-stringify) | 363.2M | Not on GitHub | Nov 2026 | MIT |

Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[JSON5](#json) has the most monthly downloads in this comparison, at 1.2B.

## Capabilities

| Library | Parses commented input | Deterministic key sorting | Preserves cyclic references |
| --- | --- | --- | --- |
| [JSON5](#json) | Yes | No | No |
| [fast-json-stable-stringify](#fast-json-stable-stringify) | No | Yes | No |
| [flatted](#flatted) | No | No | Yes |
| [parse-json](#parse-json) | No | No | No |
| [json-stable-stringify-without-jsonify](#json-stable-stringify-without-jsonify) | No | Yes | No |
| [@ungap/structured-clone](#ungap-structured-clone) | No | No | Yes |
| [jsonc-parser](#jsonc-parser) | Yes | No | No |
| [safe-stable-stringify](#safe-stable-stringify) | No | Yes | No |

## Libraries

### JSON5

[GitHub](https://github.com/json5/json5) · [npm](https://www.npmjs.com/package/json5) · [Docs](https://cdn.jsdelivr.net/npm/json5@2.2.3/README.md)

Parses and serializes configuration text with syntax beyond standard JSON.

- Downloads / mo: 1.2B
- Stars: 7.2K
- Last release: 2.2.3
- License: MIT
- Capabilities: [From the JSON5 docs](https://cdn.jsdelivr.net/npm/json5@2.2.3/README.md)

**Strengths**

- **Accepts configuration comments.** Keep single-line or multi-line comments in configuration files.
- **Reads standard JSON too.** Parse existing valid JSON files without converting their syntax.

**Watch out for**

- **Targets human-edited configuration.** Use JSON for machine-to-machine communication.

```sh
npm install json5@2.2.3
```

**react/react** (252.7K stars)

[react/react](https://github.com/react/react) 

```javascript
export function parseConfigOverrides(configOverrides: string): any {
  const trimmed = configOverrides.trim();
  if (!trimmed) {
    return {};
  }
  return JSON5.parse(trimmed);
}

```

[compiler/apps/playground/lib/compilation.ts](https://github.com/react/react/blob/1cd5eb8e0edb0b3a1ba33de9c886d91627f8b5ac/compiler/apps/playground/lib/compilation.ts#L172-L178) · [More projects using JSON5 →](https://dashboard.exa.ai/playground/search?q=JavaScript%20TypeScript%20applications%20using%20json5%20for%20configuration%20parsing%20circular%20serialization%20exact%20numeric%20JSON%20and%20schema%20based%20output&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
const JSON5 = require('json5');

const config = JSON5.parse('{ enabled: true, }');

```

From [README.md](https://cdn.jsdelivr.net/npm/json5@2.2.3/README.md)

### fast-json-stable-stringify

[GitHub](https://github.com/epoberezkin/fast-json-stable-stringify) · [npm](https://www.npmjs.com/package/fast-json-stable-stringify) · [Docs](https://cdn.jsdelivr.net/npm/fast-json-stable-stringify@2.1.0/README.md)

Stringifies objects with their keys in sorted order for a deterministic result.

- Downloads / mo: 811.8M
- Last release: 2.1.0
- License: MIT
- Capabilities: [From the fast-json-stable-stringify docs](https://cdn.jsdelivr.net/npm/fast-json-stable-stringify@2.1.0/README.md)

**Strengths**

- **Custom key comparison.** A comparison function sets the order of object keys in the output.

```sh
npm install fast-json-stable-stringify@2.1.0
```

**comet-ml/opik** (23.5K stars)

[comet-ml/opik](https://github.com/comet-ml/opik) 

```javascript
async contentHash(): Promise<string> {
  const content: Record<string, unknown> = { ...this.getContent() };

  if (this.evaluators && this.evaluators.length > 0) {
    content["evaluators"] = this.evaluators;
  }

  if (
    this.executionPolicy &&
    Object.keys(this.executionPolicy).length > 0
  ) {
    content["executionPolicy"] = this.executionPolicy;
  }

  // Use fast-json-stable-stringify for deterministic JSON
  const json = stringify(content);

  // Use xxhash32 with a seed value for hashing
  const hashFn = await initHashApi();
  const hash = hashFn.h32(json, 0xabcd).toString(16);

  return hash;
}

```

[sdks/typescript/src/opik/dataset/DatasetItem.ts](https://github.com/comet-ml/opik/blob/09b3d10b794cdc2524a7524458d4c1e5930ba023/sdks/typescript/src/opik/dataset/DatasetItem.ts#L77-L99) · [More projects using fast-json-stable-stringify →](https://dashboard.exa.ai/playground/search?q=fast-json-stable-stringify%20GitHub%20projects)

**Quickstart**

```javascript
const stringify = require('fast-json-stable-stringify');

const text = stringify({ b: 2, a: 1 });

```

From [README.md](https://cdn.jsdelivr.net/npm/fast-json-stable-stringify@2.1.0/README.md)

### flatted

[GitHub](https://github.com/WebReflection/flatted) · [npm](https://www.npmjs.com/package/flatted) · [Docs](https://cdn.jsdelivr.net/npm/flatted@3.4.4/README.md)

Serializes and restores circular object structures using a paired wire format.

- Downloads / mo: 797.9M
- Stars: 1.2K
- Last release: 3.4.4
- License: ISC
- Capabilities: [From the flatted docs](https://cdn.jsdelivr.net/npm/flatted@3.4.4/README.md)

**Strengths**

- **Restores circular object links.** Pair stringify and parse to round-trip recursive structures.
- **Filters values during serialization.** Pass a replacer to control which values stringify emits.

**Watch out for**

- **Requires its matching parser.** Pair flatted output with flatted.parse to restore references correctly.
- **Supports JSON-compatible values only.** Objects such as sockets do not round-trip as their original classes.

```sh
npm install flatted@3.4.4
```

**devhubapp/devhub** (10.2K stars)

[devhubapp/devhub](https://github.com/devhubapp/devhub) 

```javascript
export function useWhyDidYouUpdate(
  name: string,
  props: Record<string, any>,
  {
    onChangeFound,
    onNoChangeFound,
  }: {
    onChangeFound?: (data: {
      changesObj: Record<
        string,
        { from: any; to: any; isDeepEqual: boolean; changedKeys?: string[] }
      >
    }) => void
    onNoChangeFound?: () => void
  } = {},
) {
  const latestProps = useRef(props)

  useEffect(() => {
    if (!__DEV__) return

    const allKeys = Object.keys({ ...latestProps.current, ...props })

    const changesObj: Record<
      string,
      { from: any; to: any; isDeepEqual: boolean; changedKeys?: string[] }
    > = {}
    allKeys.forEach((key) => {
      if (latestProps.current[key] !== props[key]) {
        changesObj[key] = {
          from: latestProps.current[key],
          to: props[key],
          changedKeys:
            props[key] && typeof props[key] === 'object'
              ? Object.keys(latestProps.current[key])
                  .map((k) =>
                    latestProps.current[key][k] === props[key][k] ? '' : k,
                  )
                  .filter(Boolean)
              : undefined,
          isDeepEqual: _.isEqual(latestProps.current[key], props[key]),
        }
      }
    })

    if (Object.keys(changesObj).length) {
      if (onChangeFound) {
        onChangeFound({ changesObj })
      } else {
        // eslint-disable-next-line no-console
        console.log('[why-did-you-update]', name, {
          changes: flatted.parse(flatted.stringify(changesObj)),
          props: { from: latestProps.current, to: props },
        })
      }
    } else if (onNoChangeFound) {
      onNoChangeFound()
    }

    latestProps.current = props
  })
}

```

[packages/components/src/hooks/use-why-did-you-update.ts](https://github.com/devhubapp/devhub/blob/1d0d66a388245b43582b3f478846b1c470dd88a3/packages/components/src/hooks/use-why-did-you-update.ts#L23-L84) · [More projects using flatted →](https://dashboard.exa.ai/playground/search?q=JavaScript%20TypeScript%20applications%20using%20flatted%20for%20configuration%20parsing%20circular%20serialization%20exact%20numeric%20JSON%20and%20schema%20based%20output&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
const { stringify } = require('flatted');

const value = {};
value.self = value;
const text = stringify(value);

```

From [README.md](https://cdn.jsdelivr.net/npm/flatted@3.4.4/README.md)

### parse-json

[GitHub](https://github.com/sindresorhus/parse-json) · [npm](https://www.npmjs.com/package/parse-json) · [Docs](https://cdn.jsdelivr.net/npm/parse-json@8.3.0/readme.md)

Parses JSON and throws errors that show the failing line in a code frame.

- Downloads / mo: 727.1M
- Last release: 8.3.0
- License: MIT
- Capabilities: [From the parse-json docs](https://cdn.jsdelivr.net/npm/parse-json@8.3.0/readme.md)

**Strengths**

- **Names the source file.** An optional filename appears in the error message.

**Watch out for**

- **Throws on invalid JSON.** A parsing error throws a JSONError rather than returning a partial value.

```sh
npm install parse-json@8.3.0
```

**bigcommerce/stencil-cli** (110 stars)

[bigcommerce/stencil-cli](https://github.com/bigcommerce/stencil-cli) 

```javascript
export function parse(jsonString, file = '') {
    try {
        return parseJson(jsonString);
    } catch (e) {
        throw new Error(`${file} - ${e.message}`);
    }
}

```

[lib/parse-json.js](https://github.com/bigcommerce/stencil-cli/blob/f0163059fcbf3e0ea87931fd232c21e7f0199a3b/lib/parse-json.js#L3-L9) · [More projects using parse-json →](https://dashboard.exa.ai/playground/search?q=parse-json%20GitHub%20projects)

**Quickstart**

```javascript
import parseJson from 'parse-json';

const value = parseJson('{"enabled":true}');

```

From [readme.md](https://cdn.jsdelivr.net/npm/parse-json@8.3.0/readme.md)

### json-stable-stringify-without-jsonify

[GitHub](https://github.com/samn/json-stable-stringify) · [npm](https://www.npmjs.com/package/json-stable-stringify-without-jsonify) · [Docs](https://cdn.jsdelivr.net/npm/json-stable-stringify-without-jsonify@1.0.1/readme.markdown)

Stringifies objects deterministically without the unlicensed jsonify dependency.

- Downloads / mo: 700.0M
- Last release: 1.0.1
- License: MIT
- Capabilities: [From the json-stable-stringify-without-jsonify docs](https://cdn.jsdelivr.net/npm/json-stable-stringify-without-jsonify@1.0.1/readme.markdown)

**Strengths**

- **Consistent hashes.** Equal objects produce the same string and the same hash.

```sh
npm install json-stable-stringify-without-jsonify@1.0.1
```

**eslint/eslint** (27.6K stars)

[eslint/eslint](https://github.com/eslint/eslint) 

```javascript
function hashOfConfigFor(config) {
	if (!configHashCache.has(config)) {
		configHashCache.set(
			config,
			hash(`${pkg.version}_${nodeVersion}_${stringify(config)}`),
		);
	}

	return configHashCache.get(config);
}

```

[lib/cli-engine/lint-result-cache.js](https://github.com/eslint/eslint/blob/48207902fccd37450823b8fd07736d84449ec8e7/lib/cli-engine/lint-result-cache.js#L53-L62) · [More projects using json-stable-stringify-without-jsonify →](https://dashboard.exa.ai/playground/search?q=json-stable-stringify-without-jsonify%20GitHub%20projects)

**Quickstart**

```javascript
const stringify = require('json-stable-stringify-without-jsonify');

const text = stringify({ b: 2, a: 1 });

```

From [readme.markdown](https://cdn.jsdelivr.net/npm/json-stable-stringify-without-jsonify@1.0.1/readme.markdown)

### @ungap/structured-clone

[GitHub](https://github.com/ungap/structured-clone) · [npm](https://www.npmjs.com/package/@ungap/structured-clone) · [Docs](https://cdn.jsdelivr.net/npm/@ungap/structured-clone@1.4.0/README.md)

Clones and serializes values with types beyond JSON, including recursive data, as a structuredClone polyfill.

- Downloads / mo: 493.6M
- Last release: 1.4.0
- License: ISC
- Capabilities: [From the @ungap/structured-clone docs](https://cdn.jsdelivr.net/npm/@ungap/structured-clone@1.4.0/README.md)

**Strengths**

- **Serialized output is JSON-safe.** Recursive values pass through JSON.stringify and deserialize intact.

**Watch out for**

- **No Blob or File support.** Blob, File, ImageBitmap, and other non-JavaScript types are not supported yet.

```sh
npm install @ungap/structured-clone@1.4.0
```

**decentralized-identity/veramo** (547 stars)

[decentralized-identity/veramo](https://github.com/decentralized-identity/veramo) 

```javascript
async importDID(args: IIdentifier) {
  const oldTree = deserialize(serialize(this.cacheTree, { lossy: true }))
  this.cacheTree.dids[args.did] = args
  args.keys.forEach((key) => {
    this.cacheTree.keys[key.kid] = {
      ...key,
      // FIXME: keys should be able to associate with multiple DIDs
      meta: { ...key.meta, did: args.did },
    }
  })

  await this.notifyUpdate(oldTree, this.cacheTree)
  return true
}

```

[packages/data-store-json/src/identifier/did-store.ts](https://github.com/decentralized-identity/veramo/blob/ac953d9a28db1faa57266636de7c4ed891bf1b0b/packages/data-store-json/src/identifier/did-store.ts#L84-L97) · [More projects using @ungap/structured-clone →](https://dashboard.exa.ai/playground/search?q=%40ungap/structured-clone%20GitHub%20projects)

**Quickstart**

```javascript
import { stringify } from '@ungap/structured-clone/json';

const text = stringify({ any: 'serializable' });

```

From [README.md](https://cdn.jsdelivr.net/npm/@ungap/structured-clone@1.4.0/README.md)

### jsonc-parser

[GitHub](https://github.com/microsoft/node-jsonc-parser) · [npm](https://www.npmjs.com/package/jsonc-parser) · [Docs](https://cdn.jsdelivr.net/npm/jsonc-parser@3.3.1/README.md)

Scans, parses, and edits JSON with JavaScript-style comments.

- Downloads / mo: 414.0M
- Last release: 3.3.1
- License: MIT
- Capabilities: [From the jsonc-parser docs](https://cdn.jsdelivr.net/npm/jsonc-parser@3.3.1/README.md)

**Strengths**

- **Computes document edits.** The modify API returns edits that insert, remove, or replace a value in a document.

**Watch out for**

- **Parses past errors.** The error list, rather than an exception, reports invalid input.

```sh
npm install jsonc-parser@3.3.1
```

**neon-solutions/add-mcp** (325 stars)

[neon-solutions/add-mcp](https://github.com/neon-solutions/add-mcp) 

```javascript
export function writeJsonConfig(
  filePath: string,
  config: ConfigFile,
  configKey: string,
): void {
  const dir = dirname(filePath);
  if (!existsSync(dir)) {
    mkdirSync(dir, { recursive: true });
  }

  let originalContent = "";
  let existingConfig: ConfigFile = {};

  if (existsSync(filePath)) {
    originalContent = readFileSync(filePath, "utf-8");
    // jsonc.parse returns undefined for empty and comment-only files.
    const parsed: unknown = jsonc.parse(originalContent);
    if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
      existingConfig = parsed as ConfigFile;
    }
  }

  // Copilot CLI ignores root keys once mcpServers exists. Fold a bare map
  // into mcpServers before writing that wrapper, or those servers vanish.
  const replaceDocument =
    configKey !== ROOT_CONFIG_KEY && isBareServerMap(existingConfig);
  if (replaceDocument) {
    existingConfig = { mcpServers: { ...existingConfig } };
  }

  dropReplacedServers(existingConfig, config, configKey);
  const mergedConfig = deepMerge(existingConfig, config);

  if (originalContent) {
    try {
      const configKeyPath = replaceDocument ? [] : jsoncPath(configKey);
      const newValue = replaceDocument
        ? mergedConfig
        : getNestedValue(mergedConfig, configKey);
      const edits = jsonc.modify(originalContent, configKeyPath, newValue, {
        formattingOptions: detectIndent(originalContent),
      });
      const updatedContent = jsonc.applyEdits(originalContent, edits);
      writeFileSync(filePath, updatedContent);
      return;
    } catch {
      // jsonc-parser failed, fall back to JSON.stringify
    }
  }

  writeFileSync(filePath, JSON.stringify(mergedConfig, null, 2));
}

```

[src/formats/json.ts](https://github.com/neon-solutions/add-mcp/blob/5eec76ba7501f77e744429cdb918feb296e3b5ac/src/formats/json.ts#L53-L104) · [More projects using jsonc-parser →](https://dashboard.exa.ai/playground/search?q=jsonc-parser%20GitHub%20projects)

**Quickstart**

```javascript
const { parse } = require('jsonc-parser');

const errors = [];
const value = parse('{ /* configuration */ "enabled": true }', errors);
if (errors.length) throw new Error('Invalid JSONC');

```

From [README.md](https://cdn.jsdelivr.net/npm/jsonc-parser@3.3.1/README.md)

### safe-stable-stringify

[GitHub](https://github.com/BridgeAR/safe-stable-stringify) · [npm](https://www.npmjs.com/package/safe-stable-stringify) · [Docs](https://cdn.jsdelivr.net/npm/safe-stable-stringify@3.0.1/readme.md)

Stringifies values deterministically and handles circular structures and BigInt instead of throwing.

- Downloads / mo: 363.2M
- Last release: 3.0.1
- License: MIT
- Capabilities: [From the safe-stable-stringify docs](https://cdn.jsdelivr.net/npm/safe-stable-stringify@3.0.1/readme.md)

**Strengths**

- **No dependencies.** The package installs with no dependencies in ESM or CommonJS projects.

**Watch out for**

- **Circular references become placeholders.** Each circular reference becomes the configured placeholder value in the output.

```sh
npm install safe-stable-stringify@3.0.1
```

**winstonjs/winston** (24.5K stars)

[winstonjs/winston](https://github.com/winstonjs/winston) 

```javascript
_doRequest(options, callback, auth, path) {
  // Prepare options for outgoing HTTP request
  const headers = Object.assign({}, this.headers);
  if (auth && auth.bearer) {
    headers.Authorization = `Bearer ${auth.bearer}`;
  }
  const req = (this.ssl ? https : http).request({
    ...this.options,
    method: 'POST',
    host: this.host,
    port: this.port,
    path: `/${path.replace(/^\//, '')}`,
    headers: headers,
    auth: (auth && auth.username && auth.password) ? (`${auth.username}:${auth.password}`) : '',
    agent: this.agent
  });

  req.on('error', callback);
  req.on('response', res => (
    res.on('end', () => callback(null, res)).resume()
  ));
  const jsonStringify = configure({
    ...(this.maximumDepth && { maximumDepth: this.maximumDepth })
  });
  req.end(Buffer.from(jsonStringify(options, this.options.replacer), 'utf8'));
}

```

[lib/winston/transports/http.js](https://github.com/winstonjs/winston/blob/ff0b79de8562bb322c390fbc82fe71c11f373428/lib/winston/transports/http.js#L236-L261) · [More projects using safe-stable-stringify →](https://dashboard.exa.ai/playground/search?q=safe-stable-stringify%20GitHub%20projects)

**Quickstart**

```javascript
const stringify = require('safe-stable-stringify');

const text = stringify({ b: 2, a: 1 });

```

From [readme.md](https://cdn.jsdelivr.net/npm/safe-stable-stringify@3.0.1/readme.md)

## FAQ

### What is structuredClone?

structuredClone is the HTML standard's function for deep copies of values, including types that JSON cannot hold. [@ungap/structured-clone](#ungap-structured-clone) supplies it as a polyfill and also exports a serializer whose output can be stringified as JSON.

### What is JSON5?

[JSON5](#json) is a superset of JSON for configuration files that people write by hand. Valid JSON files are also valid JSON5 files.

### What is JSONC?

JSONC is JSON with JavaScript-style comments. [jsonc-parser](#jsonc-parser) scans, parses, and edits JSONC documents and also reads standard JSON.

### Can JSON have comments?

Standard JSON has no comments. [JSON5](#json) and [jsonc-parser](#jsonc-parser) both parse files that contain them.

### JSON5 vs JSONC: what is the difference?

JSONC adds JavaScript-style comments to JSON. [JSON5](#json) accepts comments as well as other syntax that people use in hand-written configuration.

### How do I stringify an object with circular references?

[flatted](#flatted) writes circular references in its own format and restores them with flatted.parse. [safe-stable-stringify](#safe-stable-stringify) replaces each circular reference with a placeholder value rather than throwing.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best JavaScript JSON libraries JSON5 flatted lossless-json fast-json-stringify code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
