Convert JSON to modern C++ classes with getters and setters
Paste JSON and get modern C++ classes back instantly. Each class ships as a header with an include guard, private members, getters and setters, and nlohmann::json to_json/from_json bindings for serialization. Fixed-width integer types are chosen based on the magnitude of the values in your data.
Output format: Class — Header with getters, setters, and nlohmann::json bindings.
| Option | What it does |
|---|---|
| Root Class Name | Names the top-level Class. |
| Namespace (optional) | Wraps the generated declarations in a namespace block. |
| Field Naming Convention | One of camelCase, PascalCase, Preserve Original. Defaults to camelCase. |
| Type for null values | Either nlohmann::json or std::string, used when a key is null in every sample. |
| JSON value | C++ type |
|---|---|
| string | std::string |
| integer | int32_t |
| integer beyond 32 bits | int64_t |
| decimal | double |
| true / false | bool |
| ISO-8601 timestamp | std::chrono::system_clock::time_point |
| array | std::vector<T> |
| object | nested class |
| null | nlohmann::json (configurable) |
{
"id": 12345,
"product_name": "Wireless Mouse",
"price": 24.99,
"in_stock": true,
"tags": ["electronics", "accessories"],
"manufacturer": {
"name": "Acme Corp",
"country": "US"
}
}
#ifndef PRODUCT_H
#define PRODUCT_H
#include <cstdint>
#include <nlohmann/json.hpp>
#include <string>
#include <vector>
class Product {
public:
int32_t getId() const { return id; }
void setId(int32_t value) { id = value; }
// ...
private:
int32_t id;
std::string productName;
double price;
bool inStock;
std::vector<std::string> tags;
Manufacturer manufacturer;
};
#endif // PRODUCT_H
nlohmann/json. Each header includes <nlohmann/json.hpp> and declares to_json and from_json overloads so your classes serialize through that library without extra glue. It is a header-only dependency available through vcpkg, Conan, or as a single downloaded header.
Fixed-width types from <cstdint> make the size of each field explicit and portable, which matters when the data crosses a wire or a platform boundary. Values that exceed the range of a 32-bit integer are widened to int64_t automatically.
No. Parsing, type inference, and code generation all run in your browser using JavaScript. Your JSON is never sent to a server, and there is no account, tracking, or storage beyond your own browser.
No. The generator is free to use with no sign-up and no usage limits.
Each nested JSON object becomes its own named type, derived from the key it appeared under. Arrays of objects are widened across every element, so a field that is a whole number in one element and a fraction in another gets a type that holds both.