# miloyip/json-tutorial

**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/miloyip-json-tutorial).**

7,939 stars · 4,288 forks · C

## Links

- GitHub: https://github.com/miloyip/json-tutorial
- Homepage: https://zhuanlan.zhihu.com/json-tutorial
- awesome-repositories: https://awesome-repositories.com/repository/miloyip-json-tutorial.md

## Description

This is an educational tutorial that walks through implementing a complete JSON library from scratch in C. The project covers the full data lifecycle of JSON, including parsing text into structured in-memory representations, validating input against the specification, serializing data back into standard JSON output, and providing structured access to elements within parsed arrays and objects.

The implementation is built around a hand-written recursive descent parser that processes JSON text by matching grammar rules to build a structured data tree. Parsed values are stored in a tagged union representation with explicit type, number, string, array, and object fields, while memory is managed manually through explicit allocation and deallocation of value structures and string buffers. The library includes a compact serialization generator that produces JSON output by recursively walking the value tree and writing formatted text, along with a custom double-precision number parser that converts JSON number tokens into IEEE 754 double values.

The project covers JSON validation with clear syntax error reporting through a fixed set of integer error codes, and provides a structured query interface for retrieving and modifying elements within parsed arrays and objects. The documentation and source code are organized as a step-by-step tutorial, making the implementation accessible for learning how to build a JSON library from the ground up.

## Tags

### Education & Learning Resources

- [JSON Library Tutorials](https://awesome-repositories.com/f/education-learning-resources/json-library-tutorials.md) — Provides a hands-on tutorial that walks through implementing a full JSON library from scratch.

### Data & Databases

- [JSON Serializers](https://awesome-repositories.com/f/data-databases/data-processing-pipelines/data-serialization/json-serializers.md) — Converts internal data structures back into standard JSON text for output using a compact serializer.
- [Recursive Descent Parsers](https://awesome-repositories.com/f/data-databases/data-transformation-functions/recursive-processors/recursive-logic-implementations/recursive-descent-parsers.md) — Processes JSON text by recursively matching grammar rules to build a structured data tree.
- [Hand-Written Parser Tutorials](https://awesome-repositories.com/f/data-databases/data-transformation-functions/recursive-processors/recursive-logic-implementations/recursive-descent-parsers/hand-written-parser-tutorials.md) — Teaches building a JSON parser from scratch without relying on libraries, focusing on recursive descent techniques.
- [JSON Parsers](https://awesome-repositories.com/f/data-databases/json-parsers.md) — Parses JSON text using a hand-written recursive descent parser that produces standard-compliant internal representations. ([source](https://github.com/miloyip/json-tutorial/blob/master/.gitignore))
- [JSON Serializers](https://awesome-repositories.com/f/data-databases/data-export-utilities/json-serializers.md) — Serializes internal data structures back into standard JSON text using a compact generator. ([source](https://cdn.jsdelivr.net/gh/miloyip/json-tutorial@master/README.md))
- [Structured JSON Generation](https://awesome-repositories.com/f/data-databases/data-processing-pipelines/data-serialization/json-schema/structured-json-generation.md) — Generates valid JSON strings from internal data structures using a compact serializer. ([source](https://github.com/miloyip/json-tutorial/blob/master/.gitignore))
- [JSON Document Manipulation](https://awesome-repositories.com/f/data-databases/json-document-stores/json-document-manipulation.md) — Provides structured access to retrieve and modify elements within parsed JSON arrays and objects.

### Programming Languages & Runtimes

- [JSON Parsing](https://awesome-repositories.com/f/programming-languages-runtimes/json-parsing.md) — Parses JSON strings into structured data representations using a hand-written recursive descent parser. ([source](https://github.com/miloyip/json-tutorial/blob/master/readme.md))
- [Tutorials](https://awesome-repositories.com/f/programming-languages-runtimes/json-parsing/tutorials.md) — Teaches writing a recursive descent parser that converts JSON text into a structured data representation.
- [Manual Memory Management](https://awesome-repositories.com/f/programming-languages-runtimes/manual-memory-management.md) — Manages memory explicitly through allocation and deallocation of value structures and string buffers.
- [JSON Serialization](https://awesome-repositories.com/f/programming-languages-runtimes/json-serialization.md) — Produces JSON strings from internal data structures to enable round-trip serialization. ([source](https://github.com/miloyip/json-tutorial/blob/master/readme.md))

### Software Engineering & Architecture

- [JSON Syntax Validators](https://awesome-repositories.com/f/software-engineering-architecture/error-handling/parse-error-reporters/json-syntax-validators.md) — Validates JSON input against the specification and reports syntax errors with clear messages.
- [JSON Syntax Validators](https://awesome-repositories.com/f/software-engineering-architecture/json-schema-validation/json-syntax-validators.md) — Checks JSON input against the specification and reports syntax errors with clear messages.
- [Tagged Union Value Representations](https://awesome-repositories.com/f/software-engineering-architecture/type-representation-objects/tagged-union-value-representations.md) — Stores parsed JSON data in a tagged union structure with type, number, string, array, and object fields.
- [Compact Serialization](https://awesome-repositories.com/f/software-engineering-architecture/base64-encoding-and-decoding/compact-serialization.md) — Ships a compact serializer that walks the value tree and writes formatted JSON text to a buffer.
- [Parse Error Reporters](https://awesome-repositories.com/f/software-engineering-architecture/error-handling/parse-error-reporters.md) — Reports parsing failures through a fixed set of integer error codes returned from each parse function.
- [Syntax Validations](https://awesome-repositories.com/f/software-engineering-architecture/json-schema-validation/syntax-validations.md) — Checks whether a given string conforms to the JSON standard and reports any syntax errors. ([source](https://github.com/miloyip/json-tutorial/blob/master/readme.md))

### Part of an Awesome List

- [JSON Value Access Interfaces](https://awesome-repositories.com/f/awesome-lists/data/json-and-data-parsing/json-value-access-interfaces.md) — Provides a structured query interface for retrieving and modifying elements within parsed JSON arrays and objects. ([source](https://github.com/miloyip/json-tutorial/blob/master/readme.md))

### Networking & Communication

- [Double-Precision Number Parsers](https://awesome-repositories.com/f/networking-communication/phone-number-parsing/double-precision-number-parsers.md) — Implements a custom strtod to parse JSON number tokens into IEEE 754 double values.
