Jsonifier

June 26, 2026 ยท View on GitHub

Commit Activity License C++23

Jsonifier is fully RFC8259 compliant.

A high-performance C++ library for validating, serializing, parsing, prettifying, and minifying JSON data - very rapidly.

It achieves this through the usage of SIMD instructions as well as compile-time hash maps for efficient key lookups during parsing.


Compiler Support

CompilerStatus
MSVCVisual Studio (Latest)
GCCGCC (Latest)
CLANGClang (Latest)

Operating System Support

OSStatus
WindowsWindows (Latest)
LinuxUbuntu (Latest)
MacmacOS (Latest)

CPU Architecture Support

Jsonifier automatically detects and optimizes for your CPU architecture:

  • x64 / AMD64 - 64-bit extension of x86 with enhanced memory addressing
  • AVX - 128-bit vector registers for SIMD operations
  • AVX2 - 256-bit vector registers with additional integer operations
  • AVX-512 - 512-bit vector registers for maximum parallelism
  • ARM-NEON - SIMD instructions for ARM processors

Manual configuration is also available via JSONIFIER_CPU_FLAGS in CMake.


Features

๐Ÿš€ High Performance

  • SIMD-accelerated parsing and validation
  • Compile-time reflection eliminates runtime overhead
  • Specialized hash maps for different object sizes (1, 2, 3+ fields)
  • Zero-copy parsing where possible

๐Ÿ› ๏ธ Flexible API

  • Parse into existing objects or create new ones
  • Serialize to existing buffers or return strings
  • Partial reading for unordered or unknown JSON structures
  • Support for minified JSON optimization

๐Ÿ“‹ Complete JSON Support

  • Full RFC8259 compliance
  • Unicode and escape sequence handling
  • All JSON data types (objects, arrays, strings, numbers, booleans, null)
  • Raw JSON data preservation

๐Ÿ”ง Advanced Features

  • Runtime key exclusion during serialization
  • Custom parsing/serialization for specialized types
  • JSON validation with detailed error reporting
  • Pretty-printing with customizable indentation
  • Minification for compact output

๐Ÿ›ก๏ธ Safety & Reliability

  • Comprehensive error handling with source location tracking
  • AddressSanitizer (ASAN) and UndefinedBehaviorSanitizer (UBSAN) support
  • Continuous integration with sanitizers enabled
  • Extensive test suite including conformance tests

CI/CD with unit-tests

Jsonifier uses GitHub Actions to continuously test across multiple platforms and compilers with sanitizers enabled:

name: unit-tests
on:
  push:
    branches: [ "**" ]
  pull_request:
    branches: [ "**" ]
  workflow_dispatch:

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            compiler: clang
            name: "Ubuntu Clang"
          - os: ubuntu-latest
            compiler: gcc
            name: "Ubuntu GCC"
          - os: macos-latest
            compiler: clang
            name: "macOS Clang"
          - os: macos-latest
            compiler: gcc
            name: "macOS GCC"
          - os: windows-latest
            compiler: msvc
            name: "Windows MSVC"
    runs-on: ${{ matrix.os }}
    # ... full build and test with ASAN + UBSAN

This ensures memory safety and undefined behavior detection across all supported platforms.


Comprehensive Test Suite

Jsonifier includes an extensive test suite that runs on every push across all supported platforms and compilers with ASAN (AddressSanitizer) and UBSAN (UndefinedBehaviorSanitizer) enabled:

Test Categories

Test CategoryDescription
Conformance TestsFull RFC8259 compliance testing with 30+ JSON test files (pass/fail cases)
Round-Trip TestsSerialize โ†’ Parse โ†’ Compare to ensure data integrity across all types
Float Validation64+ edge cases including denormals, infinities, and extreme values
Integer ValidationBounds testing for signed/unsigned integers (8-bit to 64-bit)
String ValidationUnicode, escape sequences, control characters, and emoji support
Bounds/TruncationValidates behavior with truncated and malformed JSON input
Type CoveragePrimitives, containers (vector, array, map, unordered_map), tuples, optional, shared_ptr, enums

What Gets Tested

  • 100+ individual test cases covering all JSON data types
  • 30+ conformance tests from the official JSON test suite
  • 27 round-trip tests including edge cases (null, empty, large numbers, special floats)
  • Memory safety - No leaks, double-frees, or use-after-free
  • Undefined behavior - No signed overflow, null pointer dereference, or invalid casts
  • Bounds checking - Proper handling of truncated input
  • Unicode and emoji - Full UTF-8 support with emoji validation
  • Edge cases - Infinity, NaN, denormal numbers, integer overflow boundaries

Running Tests Locally

# Clone the repository
git clone https://github.com/RealTimeChris/Jsonifier.git
cd Jsonifier

# Configure with tests enabled
cmake -B build -DJSONIFIER_UNIT_TESTS=ON

# Build and run tests
cmake --build build --target jsonifier_unit_tests
./build/Tests/jsonifier_unit_tests

Quick Example

#include <jsonifier>

// Define your structure
struct Person {
    std::string name;
    int32_t age;
    double height;
    bool active;
};

// Register it with Jsonifier
template<> struct jsonifier::core<Person> {
    using value_type = Person;
    static constexpr auto parseValue = createValue<
        &value_type::name,
        &value_type::age,
        &value_type::height,
        &value_type::active
    >();
};

int main() {
    jsonifier::jsonifier_core<> parser;
    
    // Parse JSON
    std::string json = R"({"name":"John","age":30,"height":1.85,"active":true})";
    Person person;
    parser.parseJson(person, json);
    
    // Serialize to JSON
    std::string output;
    parser.serializeJson(person, output);
    // output: {"name":"John","age":30,"height":1.85,"active":true}
    
    return 0;
}

Documentation

Getting Started

  • Installation - Install via vcpkg, CMake FetchContent, or source

core Usage

Optimization

Output Formatting

  • Prettifying - Pretty-print JSON with customizable indentation
  • Minifying - Minify JSON for compact output

Advanced Topics


Requirements

  • CMake 3.18 or later
  • C++23 compliant compiler (MSVC 2022+, GCC 11+, Clang 14+)
  • Supported CPU (x64, ARM64 with NEON)

License

This library is licensed under the MIT License. See the LICENSE file for details.


Acknowledgments

  • SIMD parsing techniques inspired by simdjson
  • Reflection interface inspired by Glaze
  • Dragonbox algorithm for float conversion
  • FastFloat for number parsing

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues on GitHub.


Star this repository if you find it useful! โญ