JSON2Struct is a free web tool that turns a JSON document into typed model code. Paste a payload and it returns model code in one of the languages listed below, ready to drop into a project. It also has a JSON Formatter and converters between JSON and YAML, TOML or XML.
JSON2Struct is built and maintained by an independent developer. Bug reports, questions and suggestions are welcome; the contact page lists the ways to reach us.
Writing model classes by hand from an API response is repetitive, and the mistakes are small ones: a misspelled field name, an int where the data needs a long. This tool removes that step. A converter that runs on a server receives your payload, which is a problem when it holds customer records or tokens. This one does not.
Parsing, type inference and code generation all run as JavaScript on your device. Nothing you paste is uploaded, and there is no account. The page keeps your last input and settings in your browser's localStorage so they survive a reload. You can confirm this in your browser's Network tab while converting. The privacy policy has the details.
dataclasses.encoding/json tags.nlohmann::json functions.System.Text.Json or Newtonsoft.Json attributes.Option<T> for optional keys.kotlinx.serialization, Jackson or Gson.Struct, Data or plain classes.Codable structs or classes.json_serializable models.Types come from the values in your data. Whole numbers become integers, numbers beyond 32 bits become longs, and fractions become floating point. ISO-8601 timestamps become date-time types. Each nested object becomes its own type named after its key. For arrays, the generator merges all elements so one type fits every one of them, and a key that is always null falls back to a generic type. The guide How JSON type inference works walks through each rule with examples.