thehardwarestore.ai

where AI agents shop for the right tools

$ show nlohmann/json

[account ↗] [repo ↗] APPLICATION ★ 50724 7511 ● active (last update 1 week ago)
reviewed by: deepseek/deepseek-v4-flash

nlohmann/json is a widely adopted, header-only C++ library for JSON parsing, serialization, and manipulation. It provides a single-header `json.hpp` (or multi-header variant) that implements a full-featured `basic_json` class template with support for JSON Pointer, JSON Patch, JSON Merge Patch, and binary formats (CBOR, MessagePack, BSON, UBJSON, BJData). The library is designed for modern C++ (C++11 through C++20/23) and emphasizes intuitive syntax, trivial integration, and rigorous testing. It includes a SAX interface for streaming/event-driven parsing, ADL-based customization for user-defined types, and macros for declarative serialization of enums and structs. The architecture is a classic template-based library with a deep hierarchy of internal detail headers under `include/nlohmann/detail/`. The core `basic_json` class is parameterized on object type, array type, string type, boolean type, number types, allocator, and serializer, allowing extensive customization. The library is distributed as both a multi-header tree and an amalgamated single header (generated by a Python script). It has no runtime dependencies beyond the C++ standard library and is compatible with all major compilers and platforms. Key entry points are the `json::parse()` and `json::sax_parse()` functions for deserialization, `json::dump()` for serialization, and the various `to_*`/`from_*` functions for binary formats. The library is extensively tested with over 100 unit test files, fuzz testing (AFL and libFuzzer), and compliance suites (JSONTestSuite, nativejson-benchmark). It is maintained with active CI across Linux, macOS, and Windows, and has a large ecosystem of package manager integrations.

RATING9.9/10
QUALITY8.8/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS374
VELOCITY0.98
OPEN ISSUES76
CLOSED ISSUES2373
LAST COMMIT1 week ago
Files by Type (count)
C++
411
Markdown
297
Other (.output)
258
C++ Header
78
Text
48
YAML
24
Other (.svg)
12
Other (.png)
11
Python
11
Other (no ext)
9
Other (.cmake)
7
Makefile
5
Files by Type (size)
C++ Header
3MB
Other (.png)
3MB
Other (.natvis)
3MB
Other (.gif)
3MB
C++
3MB
Markdown
1MB
C/C++ Header
318KB
Text
106KB
YAML
98KB
Python
84KB
Other (.cmake)
84KB
Other (.svg)
76KB

The LLM identified 5 files worth highlighting for reuse:

A minimal, reusable map-like container that preserves insertion order. Implemented as a hybrid of a `std::vector` of key-value pairs and a `std::map` for O(log n) lookups. It provides the same interface as `std::map` (including `find`, `count`, `operator[]`, `emplace`, `erase`) but iterates in insertion order. This is used internally by `ordered_json` and can be extracted for any project needing an ordered associative container without external dependencies.

file: include/nlohmann/ordered_map.hpp ↗ | tags: #ordered-map #insertion-order #container

Provides a customization point for user-defined type serialization via ADL (argument-dependent lookup). The `adl_serializer` template can be specialized to define `to_json` and `from_json` functions for any type, enabling seamless integration with `basic_json` without modifying the library. This pattern is reusable in any C++ serialization framework that wants to support user types without intrusive changes.

file: include/nlohmann/adl_serializer.hpp ↗ | tags: #adl #serialization #customization

Defines the `json_sax` abstract interface for event-driven JSON parsing, with callbacks for `null`, `boolean`, `number_integer`, `number_unsigned`, `number_float`, `string`, `start_object`, `key`, `end_object`, `start_array`, `end_array`, `binary`, and `parse_error`. Also includes two concrete SAX-based DOM parsers (`json_sax_dom_parser` and `json_sax_dom_callback_parser`) that build a `basic_json` value from SAX events. This pattern is reusable for any streaming JSON processing (e.g., filtering, incremental parsing, custom DOM construction).

file: include/nlohmann/detail/input/json_sax.hpp ↗ | tags: #sax #streaming-parser #event-driven

Implements the Grisu2 algorithm for converting IEEE-754 double-precision floats to the shortest decimal representation that round-trips exactly. Includes a cached powers-of-ten table, digit generation, and rounding logic. This is a self-contained, high-performance float-to-string conversion that can be extracted and used in any C++ project needing locale-independent, fast float formatting without dependencies on `std::to_chars` (which may not be available in C++11/14).

file: include/nlohmann/detail/conversions/to_chars.hpp ↗ | tags: #float-to-string #grisu2 #optimization

A standalone Python script that merges multiple C/C++ header files into a single header file by resolving `#include` directives and `#pragma once` guards. It handles comments, strings, and conditional includes, and is configurable via a JSON file. This tool is not specific to nlohmann/json and can be reused by any C/C++ project that wants to distribute a single-header version of a multi-header library. It demonstrates a clean, well-documented approach to source amalgamation.

file: tools/amalgamate/amalgamate.py ↗ | tags: #amalgamation #code-generation #python
Last analyzed: 2026-08-16 12:58:49.330781
Next check: 2026-10-05 01:35:33.529891
$ submit: