Skip to content

Implement C++ library with C API for JSON/TOML parsing using Boost.Json and Toml++#1

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/create-c-api-with-boost-json
Draft

Implement C++ library with C API for JSON/TOML parsing using Boost.Json and Toml++#1
Copilot wants to merge 4 commits into
mainfrom
copilot/create-c-api-with-boost-json

Conversation

Copilot AI commented Nov 22, 2025

Copy link
Copy Markdown

Creates a specification format library with dual JSON/TOML support, exposing a clean C API while using modern C++17 internally.

Architecture

C API Layer (include/ryspec/ryspec.h)

  • Opaque types (ryspec_context_t, ryspec_document_t) hide implementation
  • Result codes for error handling
  • String, int64, and bool value accessors

Internal C++ Layer (src/ryspec/)

  • std::variant<boost::json::value, toml::table> for unified document representation
  • Template-based type extraction with format-specific specializations
  • RAII resource management wrapped by C create/destroy functions

Build System

  • CMake with find_package for Boost, FetchContent for Toml++
  • Shared library, demo app, and test suite

Usage

ryspec_context_t* ctx = ryspec_context_create();

ryspec_document_t* doc;
ryspec_parse_string(ctx, "{\"name\":\"example\"}", RYSPEC_FORMAT_JSON, &doc);

char name[256];
ryspec_get_string(doc, "name", name, sizeof(name));

ryspec_document_destroy(doc);
ryspec_context_destroy(ctx);

TOML parsing identical except RYSPEC_FORMAT_TOML. File parsing via ryspec_parse_file().

Implementation Notes

  • Error messages valid until next context operation (standard C pattern)
  • String buffer requires null termination handling
  • Both string and file parsing supported for each format

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Prepare a C++ and library and application using Boost.Json and Toml++ libraries, built by cmake. The library must have a C API and internal types hiding internal implementation.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits November 22, 2025 12:08
Co-authored-by: doganulus <1174212+doganulus@users.noreply.github.com>
…ntation

Co-authored-by: doganulus <1174212+doganulus@users.noreply.github.com>
Co-authored-by: doganulus <1174212+doganulus@users.noreply.github.com>
Copilot AI changed the title [WIP] Prepare C++ library and application using Boost.Json and Toml++ Implement C++ library with C API for JSON/TOML parsing using Boost.Json and Toml++ Nov 22, 2025
Copilot AI requested a review from doganulus November 22, 2025 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants