json.cpp  by jart

C++ library for JSON parsing/serialization

created 9 months ago
741 stars

Top 47.7% 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

3 days ago

Responsiveness

1 day

Pull Requests (30d)
1
Issues (30d)
1
Star History
30 stars in the last 90 days

Explore Similar Projects

Starred by Philipp Schmid Philipp Schmid(DevRel at Google DeepMind) and Stas Bekman Stas Bekman(Author of Machine Learning Engineering Open Book; Research Engineer at Snowflake).

json_repair by mangiucugna

1.1%
3k
JSON repair tool for LLM outputs
created 1 year ago
updated 1 week ago
Starred by Simon Willison Simon Willison(Author of Django), Jared Palmer Jared Palmer(Ex-VP of AI at Vercel; Founder of Turborepo; Author of Formik, TSDX), and
1 more.

GPT-3-Encoder by latitudegames

0%
719
JS library for GPT-2/GPT-3 text tokenization
created 4 years ago
updated 2 years ago
Feedback? Help us improve.