API Reference

JSON5

Parser and serializer for JSON5, the JSON superset that permits comments, trailing commas, and unquoted keys.

Official Documentation ↗
CompatibilityThis documentation covers version v2.2. Check the official docs for the latest API surface.

Installation

npmnpm install json5

Methods

JSON5 keeps JSON semantics while relaxing syntax so configuration files can be hand-edited with comments.

Key Features

  • Comments, trailing commas, and single quotes
  • Hex numbers, leading plus, and multi-line strings
  • Stringify output is always valid JSON

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Security notes

Quoted from the official documentation (https://github.com/json5/json5); this is not a complete threat model.

  • Security Vulnerabilities and Disclosures To report a security vulnerability, please follow the follow the guidelines described in our security policy. (https://github.com/json5/json5)

FAQ

What is JSON5 best used for?
Configuration files. Comments, trailing commas, and unquoted keys make hand editing friendlier while output stays JSON-compatible.
Is JSON5 output always valid JSON?
Yes. JSON5.stringify emits standard JSON, so consumers that only understand JSON can read the result.
Can JSON5 execute code like eval?
No. JSON5.parse uses a real grammar and never evaluates functions, unlike the unsafe eval approach.