Closed the-moisrex closed 2 years ago
At this moment I am not convinced that a fully constexpr version is better. But it would definitely require C++20. The project I need this for is only C++17.
See one of the JSON files that I need to be able to parse: https://github.com/lefticus/json2cpp/blob/main/examples/Energy%2B.schema.epJSON
There's basically no chance at all with current compiler implementations that this could be compile-time parsed before the heat death of the universe.
Also, without a #embed
solution, you still have to have a pre-build step of embedding the JSON into a C++ file.
This version should be easy to drop-in to any project that has JSON resources and be able to do whatever you want to at compile-time or run-time.
Aside: there are a couple of existing constexpr JSON parsers, besides the one that Ben Deane and I wrote back in 2017.
All make sense.
I'm not sure how a 9 MiB json file is gonna be used but unless all the values are needed it is possible to just dump only the necessary, pre-computed values.
But yeah, a large json file is impossible to deal with in constexpr except with a little bit of help from the build system.
We could make a manifest of the structure of the json file, embed it, and let the constexpr parser only parse the parts that we need and not the whole thing. But that's useless in cases which we need to traverse the whole thing.
So yeah the best option is code generation unfortunately.
Is there a good library/framework for code generation? I mean, if we're already tipping our toe into it, why not swim?😅
What I have here already fully works and is very very simple. Only a couple of hundred lines of code and most of that is header file description.
The goals are explicitly stated in the README.md. The goal is to get the cost of using a statically known JSON file to 0 while providing API compatibility with nlohmann::json and valison. This project accomplishes that goal.
I'm going to go ahead and close this issue, since it is not related to the goals of the project.
Is it because it's harder to implement a constexpr friendly json parser and you didn't have time for creating one that you end up doing this project, @lefticus ?
Because I was thinking about making similar thing to this but I thought a constexpr version is much better if there was any!