Skip to content

Compile-time parsing (C++26)#2534

Merged
FranciscoThiesen merged 14 commits intomasterfrom
francisco/compile-time-parsing_daniel
Nov 2, 2025
Merged

Compile-time parsing (C++26)#2534
FranciscoThiesen merged 14 commits intomasterfrom
francisco/compile-time-parsing_daniel

Conversation

@lemire
Copy link
Member

@lemire lemire commented Oct 31, 2025

This PR introduces compile-time JSON parsing for C++26 users. Essentially, at compile time, you can load a JSON file (with embed) and parse... so if you JSON is like so...

{
  "name" : "John",
  "age": 5
 
}

Then calling our simdjson::compile_time::parse_json function, you get, at compile time... something like this pseudoC++:

struct {
  const char * name = "John";
  uint64_t age = 5;
}

It is a dynamically generated structure/class.

Thus you get the following...

constexpr auto cfg = simdjson::compile_time::parse_json<R"({
    "port": 8080,
    "host": "localhost",
    "debug": true
})">();

// cfg.port == 8080
// std::string_view(cfg.host) == "localhost"
// cfg.debug == true

We support JSON that take the form of an array or an object. We support full precision number parsing, and there is a bunch of validation (including Unicode checks), all at compile time. The strings are unescaped, including for Unicode data.

Joint work with @FranciscoThiesen and huge thanks to the C++26 reflection people.

@FranciscoThiesen
Copy link
Member

Thanks for the updates to the code and for adding well-written documentation (:

@FranciscoThiesen FranciscoThiesen merged commit 86bfbaa into master Nov 2, 2025
156 checks passed
@FranciscoThiesen FranciscoThiesen deleted the francisco/compile-time-parsing_daniel branch November 2, 2025 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants