JSON to C++ Struct Generator

Paste JSON, get C++ code instantly. Private, in your browser.

Input

Output

Ready
Ln 1, Col 1

Convert JSON to C++ in one step

Paste JSON and get C++17 structs plus from_json and to_json functions for the popular header-only nlohmann/json library.

How to use it

  1. Paste a JSON sample into the Input panel, open a file, or drop it onto the page. A sample is already loaded so you can see the result.
  2. The C++ code appears instantly in the Output panel and updates as you type.
  3. Rename the top-level type under Settings → Root type name, and use Sort keys to order fields alphabetically.
  4. Copy the code or Download it as Root.hpp.

What the C++ generator produces

  • Plain structs with std::string, int64_t, double, bool and std::vector.
  • std::optional for values that can be missing or null.
  • Explicit from_json / to_json that use the original JSON keys, so any key works.
  • Types are declared in dependency order in a single header.

Using the generated C++ code

Parse with nlohmann/json:

#include "root.hpp"

auto j = nlohmann::json::parse(text);
Root data = j.get<Root>();
std::cout << data.users[0].name << "\n";

More JSON tools

All tools are free and run privately in your browser.

JSON to C++ FAQ

Which C++ standard is required?

C++17, for std::optional. nlohmann/json 3.x finds the generated from_json and to_json functions automatically.

Is my data uploaded to a server?

No. The JSON to C++ runs entirely in your browser using JavaScript. Your data is never uploaded, logged or stored, and the tool keeps working offline after your first visit.