JSON to C++ Struct Generator
Generate C++ structs with nlohmann/json deserializers from JSON data. Produces typed fields with proper type mapping including std::vector, std::optional, and nested struct generation.
Features
⚙️ Modern C++ Types
- std::string for string fields
- std::vector<T> for arrays
- std::optional<T> for nullable fields
- Nested struct generation
📦 nlohmann/json
- from_json() deserializers
- j.at("key").get_to(field) pattern
- Header-only library support
- Automatic #include headers
🔧 Type Mapping
- JSON integer → int
- JSON float → double
- JSON boolean → bool
- JSON null → std::optional
C++ nlohmann/json Guide
Using nlohmann/json
nlohmann/json is a popular header-only C++ library for JSON. Add it to your project and define from_json() for automatic deserialization.
// Install via CMake or download single header: // https://github.com/nlohmann/json/releases // #include <nlohmann/json.hpp>
#include <string>
#include <nlohmann/json.hpp>
struct User {
int id;
std::string name;
bool active;
};
void from_json(const nlohmann::json& j, User& o) {
j.at("id").get_to(o.id);
j.at("name").get_to(o.name);
j.at("active").get_to(o.active);
}
// Usage:
// nlohmann::json j = nlohmann::json::parse(jsonString);
// User u = j.get<User>();