Skip to content

RealTimeChris/Jsonifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

34 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Jsonifier

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

Compiler Status
MSVC Visual Studio (Latest)
GCC GCC (Latest)
CLANG Clang (Latest)

Operating System Support

OS Status
Windows Windows (Latest)
Linux Ubuntu (Latest)
Mac macOS (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 Sanitizers

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

name: Sanitizers
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 Category Description
Conformance Tests Full RFC8259 compliance testing with 30+ JSON test files (pass/fail cases)
Round-Trip Tests Serialize β†’ Parse β†’ Compare to ensure data integrity across all types
Float Validation 64+ edge cases including denormals, infinities, and extreme values
Integer Validation Bounds testing for signed/unsigned integers (8-bit to 64-bit)
String Validation Unicode, escape sequences, control characters, and emoji support
Bounds/Truncation Validates behavior with truncated and malformed JSON input
Type Coverage Primitives, 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/Index.hpp>

// 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! ⭐

About

A few classes for extremely fast json parsing/serializing in modern C++. Possibly the fastest json parser in C++. Possibly the fastest json serializer in C++.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

 
 
 

Contributors