json.cpp  by jart

C++ library for JSON parsing/serialization

Created 10 months ago
754 stars

Top 46.1% on SourcePulse

GitHubView on GitHub
Project Summary

This library provides a C++ JSON parser and serializer optimized for performance and minimal code size, targeting developers who need a fast, lightweight, and hackable JSON solution for classic C++ environments. It aims to be significantly faster and smaller than modern C++ alternatives like nlohmann/json, while maintaining high conformance with the JSONTestSuite.

How It Works

The library employs a C-style parsing approach, prioritizing speed and simplicity over extensive C++ template metaprogramming. It leverages Google's double-conversion library for efficient floating-point serialization, preserving float precision without upcasting to double. This design choice results in a smaller codebase and faster compilation times compared to more feature-rich C++ JSON libraries.

Quick Start & Requirements

  • Install: Compile json.cpp and json.h into your project.
  • Dependencies: Google's double-conversion library.
  • Links: JSONTestSuite

Highlighted Details

  • Claims 2x-3x faster parsing and 10x faster compilation than nlohmann/json.
  • Passes all JSONTestSuite conformance tests, with specific noted failures for certain UTF-8 edge cases.
  • Preserves float precision during serialization, unlike libraries that upcast to double.
  • Features a minimal codebase: 233 lines for json.h and 1,303 lines for json.cpp.

Maintenance & Community

Originally developed for Redbean in C, it was converted to C++ for Mozilla's llamafile project in 2024.

Licensing & Compatibility

The library is licensed under the MIT License, allowing for commercial use and integration into closed-source projects.

Limitations & Caveats

The library exhibits IMPLEMENTATION_FAIL for several JSONTestSuite cases related to malformed UTF-8, overlong sequences, and control codes within strings. It also fails on deeply nested arrays (depth_exceeded).

Health Check
Last Commit

1 month ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
0
Star History
9 stars in the last 30 days

Explore Similar Projects

Starred by Chris Van Pelt Chris Van Pelt(Cofounder of Weights & Biases), Stas Bekman Stas Bekman(Author of "Machine Learning Engineering Open Book"; Research Engineer at Snowflake), and
4 more.

tensorizer by coreweave

0.4%
265
Module for fast model serialization/deserialization
Created 2 years ago
Updated 4 weeks ago
Feedback? Help us improve.