Repository navigation
JsonParser v1.0.0
The first stable release of JsonParser, an RFC 8259–compliant JSON library for modern C++.
Highlights
- Single-pass recursive-descent parser, strictly conforming to RFC 8259.
- Insertion-order-preserving object type (
JsonObject) backed by a vector plus a transparent-hash index. Jsonvalue type covering Null, Bool, Number, String, Array, and Object, backed bystd::variant.parse()(copies input) andparseOwned()(takes ownership) entry points.- Lossless, round-trip-exact number serialization via
std::to_chars. - Bounds-checked (
at()) and unchecked (operator[]) access for both arrays and objects. - Full
\uescape support, including surrogate-pair decoding to astral-plane codepoints. - Configurable maximum nesting depth guard against malicious or malformed deeply-nested input.
- A dedicated exception hierarchy:
JsonParseError(with line/column),JsonTypeError,JsonOutOfRange. - Order-independent structural equality (
operator==) for arrays and objects. - Thread-safe for concurrent const access to a shared value, with no internal synchronization overhead.
- Distributed as a vcpkg port and a Conan recipe, alongside plain CMake
find_package()support.
Performance
The implementation favors allocation-light parsing and cache-friendly storage over branch-light scalar access.
- Single-pass parsing avoids intermediate tokenization — numbers are validated and converted directly via
std::from_chars. JsonObject's vector-plus-hash-index layout gives O(1) average lookup while keepingdump()a straight cache-friendly walk, with no separate order-tracking structure.- String serialization scans and bulk-appends unescaped runs, so only actual escapes and control characters pay a per-character cost.
- The trade-off:
std::variant'sget_ifaccess pattern costs more per call than a hand-rolled tagged union on trivial scalar operations (type(),isX(),operator[]) — where nlohmann::json's simpler storage wins outright.
Benchmarks
Measured against nlohmann::json at 10K / 100K / 1M iterations. Full results: benchmarks/results/v1_0_0.md.
| Operation | JsonPro (1M) | nlohmann::json (1M) | Δ |
|---|---|---|---|
| Short String Copy | 6.21 ms | 25.50 ms | +310.4% |
| Parse Number Array | 480.96 ms | 1.70 s | +253.7% |
| Default Copy | 1.71 ms | 5.91 ms | +246.2% |
| Contains() Miss | 15.98 ms | 52.65 ms | +229.5% |
| Default Move | 4.71 ms | 12.08 ms | +156.6% |
| Round-trip String-heavy Object | 2.68 s | 4.82 s | +80.1% |
| Compare Equal Arrays | 8.90 ms | 13.99 ms | +57.2% |
| Round-trip Small Object | 2.71 s | 3.77 s | +39.1% |
| Object Copy | 154.25 ms | 199.08 ms | +29.1% |
| Array Operator[] | 2.21 ms | 628.59 us | -71.5% |
| Type() | 1.56 ms | 308.33 us | -80.2% |
| AsBool() | 1.86 ms | 317.37 us | -82.9% |
JsonPro's single-pass parser and hash-indexed object storage pay off most on
parsing (Parse Number Array), copy/move of scalar and container values, and
miss-heavy lookups (Contains() Miss) — all cases where nlohmann::json's
tree-of-std::map design or heavier per-value overhead shows up directly.
The trade-off: std::variant's get_if-based access costs more per call than
nlohmann::json's storage on trivial scalar operations (operator[], type(),
asBool()), so those benchmarks favor nlohmann::json instead.
Testing
The project includes a comprehensive test suite covering:
- Unit tests
- Integration tests
- Lifecycle tests
- Concurrency tests
- Regression tests
- Move semantics
- Copy semantics
- Exception safety
- Parser maximum nesting depth
- Duplicate object key resolution
JsonObjecterase/reindex consistency- Surrogate pair decoding
- Non-finite number rejection on serialization
- Trailing input rejection
Code Coverage
The current test suite achieves:
- 93.5% line coverage
- 100.0% function coverage
Coverage reports exclude test infrastructure and third-party dependencies, focusing on the JsonParser library implementation.
Continuous Integration
Automated builds and tests are configured for:
- GCC — Debug
- GCC — Release
- Clang — Debug
- Clang — Release
- MSVC — Debug
- MSVC — Release
- AppleClang — Debug
- AppleClang — Release
Release
This release represents the first stable version of JsonPro and
establishes the initial parsing/serialization API, exception hierarchy,
JsonObject storage design, testing infrastructure, and packaging support.
Installation
Available as a vcpkg port or a Conan recipe, or via plain CMake
find_package(JsonPro CONFIG REQUIRED) against a local install.
See the project documentation for build instructions, API usage, and integration details.