Repo symbol

json_struct repository

c-plus-plus serialization json parse deserialization template-metaprogramming template-specialisations
Repo symbol

json_struct repository

c-plus-plus serialization json parse deserialization template-metaprogramming template-specialisations
Repo symbol

json_struct repository

c-plus-plus serialization json parse deserialization template-metaprogramming template-specialisations
Repo symbol

json_struct repository

c-plus-plus serialization json parse deserialization template-metaprogramming template-specialisations
Repo symbol

json_struct repository

c-plus-plus serialization json parse deserialization template-metaprogramming template-specialisations json_struct

Repository Summary

Description json_struct is a single header only C++ library for parsing JSON directly to C++ structs and vice versa
Checkout URI https://github.com/jorgen/json_struct.git
VCS Type git
VCS Version master
Last Updated 2025-10-11
Dev Status UNKNOWN
Released UNRELEASED
Tags c-plus-plus serialization json parse deserialization template-metaprogramming template-specialisations
Contributing Help Wanted (-)
Good First Issues (-)
Pull Requests to Review (-)

Packages

Name Version
json_struct 0.0.1

README

Structurize your JSON

CI ClusterFuzzLite PR fuzzing

json_struct is a single-header C++ library that parses JSON to structs/classes and serializes structs/classes back to JSON. With support for relaxed parsing rules, it’s also excellent for configuration files and human-editable data formats.

Getting Started: Simply copy json_struct.h from the include folder into your project’s include path.

Requirements: C++11 or newer. Tested on GCC, Clang, and Visual Studio 2015+.

Quick Start

json_struct automatically maps JSON to C++ structs by adding simple metadata declarations.

{
    "One" : 1,
    "Two" : "two",
    "Three" : 3.333
}

can be parsed into a structure defined like this:

struct JsonObject
{
    int One;
    std::string Two;
    double Three;

    JS_OBJ(One, Two, Three);
};

or

struct JsonObject
{
    int One;
    std::string Two;
    double Three;
};
JS_OBJ_EXT(JsonObject, One, Two, Three);

Parse JSON to struct:

JS::ParseContext context(json_data);
JsonObject obj;
context.parseTo(obj);

Serialize struct to JSON:

std::string pretty_json = JS::serializeStruct(obj);
// or
std::string compact_json = JS::serializeStruct(obj, JS::SerializerOptions(JS::SerializerOptions::Compact));

Relaxed Parsing for Config Files

json_struct supports relaxed JSON parsing rules, making it ideal for configuration files and human-editable data. Enable optional features for a more forgiving syntax:

  • Comments using // syntax
  • Unquoted property names and string values (supports A-Z, a-z, 0-9, _, -, ., /)
  • Newlines instead of commas as delimiters
  • Trailing commas in objects and arrays

Example configuration file:

{
  // Server configuration
  host: localhost
  port: 8080

  database: {
    name: myapp_db
    max_connections: 100,  // Trailing comma is OK
  }

  log_file: /var/log/app.log
}

Enable relaxed parsing:

JS::ParseContext context(config_data);
context.tokenizer.allowComments(true);
context.tokenizer.allowAsciiType(true);
context.tokenizer.allowNewLineAsTokenDelimiter(true);
context.tokenizer.allowSuperfluousComma(true);
context.parseTo(config_obj);

Dynamic JSON with Maps

File truncated at 100 lines see the full file

Repo symbol

json_struct repository

c-plus-plus serialization json parse deserialization template-metaprogramming template-specialisations
Repo symbol

json_struct repository

c-plus-plus serialization json parse deserialization template-metaprogramming template-specialisations
Repo symbol

json_struct repository

c-plus-plus serialization json parse deserialization template-metaprogramming template-specialisations
Repo symbol

json_struct repository

c-plus-plus serialization json parse deserialization template-metaprogramming template-specialisations