explaingit

tencent/rapidjson

15,056C++Audience · developerComplexity · 3/5StaleLicenseSetup · easy

TLDR

A fast header-only C++ library for parsing and writing JSON with both DOM and SAX APIs, full Unicode support and JSON Schema validation.

Mindmap

mindmap
  root((RapidJSON))
    Inputs
      JSON text
      Streams
      Schemas
    Outputs
      DOM tree
      SAX events
      Serialised JSON
    Use Cases
      Game engines
      Embedded systems
      Backend services
      Config parsing
    Tech Stack
      C++
      Header-only
      CMake
      SSE
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Parse and serialise JSON config files in a C++ game or desktop app without pulling in Boost.

USE CASE 2

Stream-parse a multi-gigabyte JSON log with the SAX API while keeping memory flat.

USE CASE 3

Validate incoming API payloads in a C++ backend using JSON Schema.

USE CASE 4

Transcode JSON strings between UTF-8 and UTF-16 for a Windows native app.

Tech stack

C++CMakeSSEUnicode

Getting it running

Difficulty · easy Time to first run · 30min

Header-only, so copy include/rapidjson into your project or install via vcpkg, CMake is only needed if you want to build the bundled tests.

MIT licensed open source, free to use commercially with attribution, some bundled third-party code uses BSD or JSON-license terms.

In plain English

RapidJSON is a C++ library for reading and writing JSON, the lightweight text format that web APIs use to send data around. The library was written by Milo Yip, released by Tencent as open source, and was inspired by an earlier XML library called RapidXml. It offers two programming styles: a DOM style, where you load the whole document into an in-memory tree you can inspect and edit, and a SAX style, where the parser fires events as it reads each piece of input so you can handle them on the fly. The README emphasises that the library is small, self-contained, and header-only. You do not need to link against another build artefact or pull in heavy dependencies like Boost or the C++ standard template library, copying the include folder into your project is enough. It is also designed to be fast: the README claims parsing speed comparable to strlen, with optional SSE2 or SSE4.2 acceleration. Memory use is tight, with each JSON value occupying 16 bytes on most 32 and 64-bit machines, not counting any text strings inside it. Unicode is taken seriously. RapidJSON supports UTF-8, UTF-16, and UTF-32 (big and little endian), can detect and validate them, and can transcode between them, so you can read a UTF-8 file and store strings as UTF-16 inside the in-memory document. Null characters and surrogate pairs are supported. The library aims for full RFC 7159 and ECMA-404 compliance, with optional support for a relaxed syntax that allows comments, trailing commas, and NaN or Infinity. Version 1.1, released in August 2016, added JSON Pointer for navigating into a document by path, JSON Schema for validating documents, the relaxed syntax options, range-based for loops over arrays and objects, and a memory layout change that dropped each value from 24 bytes to 16 on x86-64. Installation is straightforward because there is nothing to compile: copy include/rapidjson into your build path, or install through vcpkg. CMake is used when you want to build the bundled tests and examples. The README ends with a short DOM example that parses a JSON string, increments the stars field, and prints the result back out, plus links to many sample programs covering both APIs. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
Show me a minimal CMake setup that adds RapidJSON via vcpkg and parses a config.json into a struct.
Prompt 2
Write a C++ function using the SAX API to extract every 'price' field from a 5GB JSON file without loading it all into memory.
Prompt 3
Validate this JSON payload against this JSON Schema using RapidJSON and print the failing path: <paste both>.
Prompt 4
Compare RapidJSON and nlohmann::json for a server that handles 50k requests per second of small JSON payloads.
Prompt 5
Use RapidJSON to read a UTF-8 file, change one field and write it back out as compact UTF-16 little endian.
Open on GitHub → Explain another repo

← tencent on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.