#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main() {
json obj = json::object();
auto ptr = json::json_pointer("/a/b/01/d");
#ifdef INIT
obj[json::json_pointer("/a/b")] = json::object();
#endif
obj[ptr] = "value";
std::cout << obj << std::endl; // prints {"a":{"b":{"01":{"d":"value"}}}}
}
Discussed in #5356
Originally posted by samcmill August 3, 2026
The following code throws a
parse_error.106exception due to the01token.However, if the first part of the JSON object up to
01is pre-initialized, then the '01' token is treated as a string and the code runs successfully.Related: #4446