JSON to C++ Struct
Runs entirely in your browser — your JSON is never uploaded to a server. No ads injected into the output, no sign-up, no sample data kept.
How to generate a C++ struct from JSON
- Paste your JSON. Paste one representative JSON object into the box above.
- Generate the struct. Click Generate C++ struct. The tool infers a type for every field and emits a struct for the root and each nested object with the required headers.
- Deserialize with nlohmann/json. Add NLOHMANN_DEFINE_TYPE_INTRUSIVE for each struct and call json::parse(str).get<Root>().
How the type mapping works
Each JSON value maps to a C++ type: a whole number becomes int64_t, a decimal becomes double, a string becomes std::string, true/false becomes bool, and null becomes std::nullptr_t. Arrays become std::vector<T> using the type of the first element.
Arrays and nested objects
Every nested object gets its own struct so the model compiles cleanly. The output includes the standard headers it needs (<string>, <vector>, <cstdint>).
Using the result with nlohmann/json
Add NLOHMANN_DEFINE_TYPE_INTRUSIVE (or a from_json/to_json pair) for each struct, then deserialize with json j = json::parse(str); Root r = j.get<Root>();.
FAQ
Is this for nlohmann/json?
Yes — the structs are plain and work with nlohmann/json. Add NLOHMANN_DEFINE_TYPE_INTRUSIVE(Root, ...) for each struct, then use j.get<Root>() to deserialize.
Why int64_t and double?
JSON has one number type. The tool picks int64_t for whole numbers and double for decimals. Narrow to int32_t or a fixed type where the real range is known.
How are arrays handled?
An array becomes std::vector<T> using the type of its first element. An empty array falls back to std::vector<nlohmann::json>.