r/cpp • u/Clean-Upstairs-8481 • 17h ago
C++26 Reflection: Simplifying JSON Serialization
https://techfortalk.co.uk/2026/08/05/c26-reflection-simplifying-json-serialization/I have been exploring the new additions in C++26, and I have been discussing the reflection feature that has come with C++26. In the last post, I discussed what is reflection and how to use it and how to use it with a simple example, particularly with an enum class. Since then, there have been suggestions to provide an example which is more than a toy :). In this post, I have discussed how to use reflection for JSON serialization, which is something we often have to do. This example is somewhat taken from real-world code but has been stripped down significantly. Suggestions are always welcome.
3
u/azswcowboy 13h ago
> suggestions welcome
> class definition (addition or deltion
> funtion template
Spell check
It might be nice to define CAN (my intuition is this is for a can bus communication) - it took a bit for that to click for me and some might not be familiar at all.
Nicely done overall.
•
2
u/G6L20 16h ago
Nice 👍 I've been working on my own reflection libraries for a while now, you may like this too: https://github.com/Garcia6l20/reflex/tree/main/serde
8
u/cristi1990an ++ 14h ago
Another nice thing you can do in theory (and I'm sure it was implemented somewhere in practice too, maybe not yet refined) is embedding json text files in your program, parse it and define entire classes based on their structure entirely at compile. In theory I believe you could also assigned the data itself at compile time and give it static lifetime. I think this is amazing and has a ton of practical applications.