
1. Generate a C++17 struct from a JSON Schema, names, types, optionality, nested data, arrays.
2. Generate C++17 code for serialising to/from the native C++17 struct. 3. Generate validation code that can emit informative messages about failed validation. Not sure about your #3, but #1 and #2 are covered by some existing tools.
Dominique, Thanks for the pointers to OpenAPI and Pistache, it's appreciated. Our recurring pattern is that we have functional-style C++ modules accepting either key-value parameters or YAML blobs along with hand coded C++ to convert to structs or classes, sometimes there is informative validation about required parameters, sometimes there are sensible defaults, but all too often there is an internal change that consumers of that interface need to be updated, but are none the wiser. (Different codebase, different team, etc) If JSON schema is rich enough to express the things we need, it's more appealing for the "plumbing" to be generated from the schema, in a similar manner to protobuf, but hopefully with much less overall complexity. C++ client application uses the generated struct to specify parameters. Same struct has support for serialising to and from JSON string. Serialising from JSON string can and should fail if not according to schema.
Essentially we want to pass state between NodeJS and core C++ modules and have those interfaces evolve over time in a maintainable way.
Quite common indeed, except for the part of the backend using C++ :). Many more backends are in JS/TS, Go, Rust, etc... than C++ I'm afraid. Thus interop with the C++ world is poorly supported by most tools. --DD
If there is a good (narrowly focused) design that seems applicable to C++ and boost::json (ideally other C++ JSON libraries too?) would be happy to hear about that. Something similar I came across just now: https://github.com/jsonrpcx/json-rpc-cxx Thanks, - Nigel Stewart On Mon, Apr 7, 2025 at 6:01 PM Dominique Devienne <ddevienne@gmail.com> wrote:
On Sun, Apr 6, 2025 at 12:58 AM Nigel Stewart via Boost-users <boost-users@lists.boost.org> wrote:
1. Generate a C++17 struct from a JSON Schema, names, types, optionality, nested data, arrays. 2. Generate C++17 code for serialising to/from the natve C++17 struct. 3. Generate validation code that can emit informative messages about failed validation.
Not sure about your #3, but #1 and #2 are covered by some existing tools.
Most from other ecosystems (JS/TS, Go, etc...) and many based on OpenAPI rather than Json schemas. Another team than mine uses Pistache for example, which generates C++ but uses nlohmann/json, and that's Linux only I think, because it does the "RPC part" also, using the Reactor pattern.
Seems to me this problem isn't specific to our application stack. Essentially we want to pass state between NodeJS and core C++ modules and have those interfaces evolve over time in a maintainable way.
Quite common indeed, except for the part of the backend using C++ :). Many more backends are in JS/TS, Go, Rust, etc... than C++ I'm afraid. Thus interop with the C++ world is poorly supported by most tools. --DD