Skip to content

Support of traits with fixed-schema JSON (Glaze/DAW) alongside DOM types #390

@StormLord07

Description

@StormLord07

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_typevariant<string_type, bool_type, array_type, ...>.
  • object_typemap<string_type, value_type>.
  • array_typevector<value_type>.
  • get_type/as_* operate on value_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_array require object_type::mapped_type == value_type and arrays of value_type. That stops us using a struct-like holder for claims, even when defining cutom struct with object_type like in jsoncons example
  • value_type is threaded through get_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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions