JSON to C++ Class

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.

Options on this page

Output format: Class — Header with getters, setters, and nlohmann::json bindings.

OptionWhat it does
Root Class NameNames the top-level Class.
Namespace (optional)Wraps the generated declarations in a namespace block.
Field Naming ConventionOne of camelCase, PascalCase, Preserve Original. Defaults to camelCase.
Type for null valuesEither nlohmann::json or std::string, used when a key is null in every sample.

How JSON values map to C++ types

JSON valueC++ type
stringstd::string
integerint32_t
integer beyond 32 bitsint64_t
decimaldouble
true / falsebool
ISO-8601 timestampstd::chrono::system_clock::time_point
arraystd::vector<T>
objectnested class
nullnlohmann::json (configurable)

Example

Input JSON

{
  "id": 12345,
  "product_name": "Wireless Mouse",
  "price": 24.99,
  "in_stock": true,
  "tags": ["electronics", "accessories"],
  "manufacturer": {
    "name": "Acme Corp",
    "country": "US"
  }
}

Generated C++

#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

Frequently asked questions

Which JSON library does the generated C++ require?

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.

Why int32_t instead of int?

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.

Is my JSON uploaded anywhere?

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.

Does it cost anything?

No. The generator is free to use with no sign-up and no usage limits.

How are nested objects handled?

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.

Other languages