C++20 Function for converting arbitrary structs to json without serialisers #4394
ptesavol
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I wrote a templated function
nlohmann::json structToJson(anyStruct)
that can convert arbitrary structs to nlohmann::json without the need of writing serialisers. Implementing the function was made possible by C++20 and boost::pfr. The function is still at proof-of-concept stage, but it can already convert quite complex nested structs that have maps and vectors of user-defined data types as members.You can try it out with the Compiler Explorer at https://godbolt.org/z/TKEo65aje
It would be nice to have similar functionality in the library itself, but I understand that it might not be realistic because of the requirement for C++20 and boost::pfr
Beta Was this translation helpful? Give feedback.
All reactions