# douglascrockford/json-js

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/douglascrockford-json-js).**

8,724 stars · 4,494 forks · JavaScript

## Links

- GitHub: https://github.com/douglascrockford/JSON-js
- Homepage: http://www.JSON.org/
- awesome-repositories: https://awesome-repositories.com/repository/douglascrockford-json-js.md

## Description

This is a JavaScript library for parsing and serializing JSON data, with a particular focus on handling objects that contain circular references. It provides a standard JSON parser that reads text and reconstructs JavaScript values without using the eval function, guarding against code injection, alongside a standard serializer that converts objects into JSON strings for data interchange.

The library distinguishes itself by offering specialized encoding and decoding for cyclical object graphs. It can serialize objects with circular references by replacing repeated object paths with JSONPath string placeholders, and then reconstruct the original graph topology from those placeholders during parsing, enabling a lossless round-trip of complex data structures. This is achieved through recursive object traversal and stack-based cycle detection during serialization, with string interning to reduce memory overhead in deeply nested structures.

The library covers the full cycle of JSON data interchange, from safe parsing and standard serialization to the specialized handling of cyclical structures. The documentation provides the source code and usage examples for the parsing and serialization functions.

## Tags

### Data & Databases

- [Lossless Graph Round-Trip Serializers](https://awesome-repositories.com/f/data-databases/graph-querying/query-graph-serialization/lossless-graph-round-trip-serializers.md) — Enables lossless round-trip serialization of object graphs with circular references.
- [JSON Parsers](https://awesome-repositories.com/f/data-databases/json-parsers.md) — Provides a safe JSON parser that reconstructs JavaScript values without eval, preventing code injection.
- [JSON Serialization Libraries](https://awesome-repositories.com/f/data-databases/json-serialization-libraries.md) — Converts JavaScript objects into JSON strings for data interchange and storage.
- [Cyclical JSON Decoders](https://awesome-repositories.com/f/data-databases/json-structure-restoration/cyclical-json-decoders.md) — Decodes JSON strings with JSONPath links to restore original object graphs with cycles intact.
- [Cyclical Structure Restorers](https://awesome-repositories.com/f/data-databases/json-structure-restoration/cyclical-structure-restorers.md) — Restores JSON strings with JSONPath links back into original object graphs with cycles intact. ([source](https://cdn.jsdelivr.net/gh/douglascrockford/json-js@master/README.md))

### Programming Languages & Runtimes

- [Cyclical Object Handlers](https://awesome-repositories.com/f/programming-languages-runtimes/javascript-interop/javascript-object-references/cyclical-object-handlers.md) — Handles encoding and recovery of JavaScript objects with circular references using JSONPath links.
- [JSON Parsing](https://awesome-repositories.com/f/programming-languages-runtimes/json-parsing.md) — Provides a standard JSON parser that reads text and reconstructs JavaScript values. ([source](http://www.json.org/))
- [Eval-Free Parsers](https://awesome-repositories.com/f/programming-languages-runtimes/json-parsing/eval-free-parsers.md) — Implements a recursive descent JSON parser that avoids eval to prevent code injection.
- [Safe Parsers](https://awesome-repositories.com/f/programming-languages-runtimes/json-parsing/safe-parsers.md) — Parses JSON strings safely without eval, guarding against code injection vulnerabilities. ([source](https://cdn.jsdelivr.net/gh/douglascrockford/json-js@master/README.md))
- [JSON Serialization](https://awesome-repositories.com/f/programming-languages-runtimes/json-serialization.md) — Converts in-memory objects into JSON strings for data interchange and storage. ([source](https://cdn.jsdelivr.net/gh/douglascrockford/json-js@master/README.md))
- [JSONPath-Based Deserializers](https://awesome-repositories.com/f/programming-languages-runtimes/object-deserialization/jsonpath-based-deserializers.md) — Ships a deserializer that resolves JSONPath placeholders to restore circular object references.
- [Cyclical Structure Serializers](https://awesome-repositories.com/f/programming-languages-runtimes/object-serialization/cyclical-structure-serializers.md) — Provides a serializer that encodes circular references using JSONPath placeholders for lossless graph serialization.

### Web Development

- [Cyclical JSON Encoders](https://awesome-repositories.com/f/web-development/json-encoding/cyclical-json-encoders.md) — Encodes objects with circular references into JSON-safe representations using JSONPath links.
- [Cyclical Structure Encoders](https://awesome-repositories.com/f/web-development/json-encoding/cyclical-structure-encoders.md) — Encodes objects with circular references into JSON-safe representations using JSONPath links. ([source](https://cdn.jsdelivr.net/gh/douglascrockford/json-js@master/README.md))
