-
-
Notifications
You must be signed in to change notification settings - Fork 299
Description
What's your question?
Is there a support of traits w/o DOM, fixed-schema structs for headers/claims, or can such support be added?
Additional Context
To my knoledge jwt-cpp’s traits assume:
value_type≈variant<string_type, bool_type, array_type, ...>.object_type≈map<string_type, value_type>.array_type≈vector<value_type>.get_type/as_*operate onvalue_type.
This is fine with DOM libraries (nlohmann/json, jsoncons, Glaze’s glz::json_t).
However, it prevents using faster fixed-schema parsing (Glaze, DAW JSON) where you want to map payloads directly to C++ structs without constructing a DOM or converting to/from one. It also makes it harder to enforce schema strictness at parse time.
I’m most familiar with Glaze (https://github.com/stephenberry/glaze). It supports both a DOM (glz::json_t) and struct-first parsing (faster, fewer allocations).
I've tried working around, creating object_type that implements [], count(), at(), but couldn't make it out because:
is_valid_json_object/is_valid_json_arrayrequireobject_type::mapped_type == value_typeand arrays ofvalue_type. That stops us using a struct-like holder for claims, even when defining cutom struct with object_type like in jsoncons examplevalue_typeis threaded throughget_type/as_*, binding the library to DOM semantics. I cant pass one single member of struct to there, or couldn't find a way.
Why this can be usefull
- Performance: struct-first parsing is typically much faster (no DOM allocation/copies).
- Safety/strictness: schema-validated claims at parse time reduce post-parse checks and surprises.
- Ecosystem: Glaze/DAW users can keep their compile-time models while still using jwt-cpp’s signing/verification. And frankly avoiding using more then one json library in project