Skip to content

Automatic conversion system between C++ structures and JSON using Boost. 🇰🇷 Boost를 사용하는 C++ 구조와 JSON 간의 자동 변환 시스템.

License

Notifications You must be signed in to change notification settings

JayTwoLab/boost.json.codec

Repository files navigation

Boost.JSON AutoDescribe Demo

Korean

Overview

This project demonstrates an automatic conversion system between C++ structures and JSON using Boost.JSON and Boost.Describe.
By defining the "field sequence" only once, it can automatically generate both the struct definition and BOOST_DESCRIBE_STRUCT declarations, reducing redundancy and improving maintainability.

Features

  • Automatic Struct Description
    Uses AutoDescribe.hpp to generate struct definitions and BOOST_DESCRIBE_STRUCT at the same time.

  • JSON Serialization / Deserialization
    JsonCodec.hpp provides easy-to-use functions to convert described structs to and from JSON using Boost.JSON.

  • Pretty Printing
    Built-in pretty printer for better readability.

  • File I/O
    Save and load JSON data directly to and from files.

  • Clang-based Code Generation
    Python tools (gen_fields.py, gen_all_structs.py) use libclang to scan headers and generate BOOST_DESCRIBE_STRUCT automatically.

Dependencies

  • Boost >= 1.75 (Tested with Boost 1.88)
  • Python 3 with clang bindings
  • libclang (LLVM)

Building

cmake -B build -S .   -DCMAKE_BUILD_TYPE=Release   -DLIBCLANG_DLL=/path/to/libclang.dll
cmake --build build

Example

hello::world::User user{"John Doe", 30, true, {"[email protected]", 95.5}, {}};
std::string json_str = JsonCodec::toString(user, true);
std::cout << json_str << std::endl;

hello::world::User loaded = JsonCodec::fromString<hello::world::User>(json_str);

License

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

About

Automatic conversion system between C++ structures and JSON using Boost. 🇰🇷 Boost를 사용하는 C++ 구조와 JSON 간의 자동 변환 시스템.

Resources

License

Stars

Watchers

Forks

Packages

No packages published