Convert JSON to C in one step
Paste JSON and get C typedef structs that mirror its shape, ready to fill with a JSON library such as cJSON or jansson.
How to use it
- 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.
- The C code appears instantly in the Output panel and updates as you type.
- Rename the top-level type under Settings → Root type name, and use Sort keys to order fields alphabetically.
- Copy the code or Download it as
Root.h.
What the C generator produces
- Strings as
char *, numbers asint64_tordouble, booleans asbool. - Optional numbers and booleans get a
has_flag; optional objects are pointers. - Arrays are a pointer plus a
_countfield. - Structs are declared in dependency order with
snake_casemembers.
Using the generated C code
Fill the structs with cJSON, for example:
cJSON *json = cJSON_Parse(text);
Root root = {0};
const cJSON *name = cJSON_GetObjectItemCaseSensitive(json, "name");
if (cJSON_IsString(name)) root.name = strdup(name->valuestring);
cJSON_Delete(json);
More JSON tools
All tools are free and run privately in your browser.
JSON FormatterBeautify, validate & convert
JSON ValidatorFind errors by line and column
JSON ViewerCollapsible tree with search
JSON MinifierCompress JSON, see bytes saved
JSON RepairFix broken JSON automatically
JSONPath TesterQuery and filter JSON
JSON EscapeStringify and unescape JSON
JSON to YAMLReadable YAML for configs
JSON to CSVArrays to spreadsheet rows
JSON to XMLWell-formed XML output
CSV to JSONSpreadsheets to JSON arrays
JSON Schema GeneratorInfer a draft 2020-12 schema
JSON to TypeScriptInterfaces with optional fields
JSON to GoStructs with json tags
JSON to JavaRecords with Jackson annotations
JSON to KotlinData classes for kotlinx.serialization
JSON to SwiftCodable structs with CodingKeys
JSON to DartFlutter models with fromJson
JSON to C#Classes for System.Text.Json
JSON to C++Structs for nlohmann/json
JSON to CTyped structs for C
JSON to PHPReadonly DTO classes
JSON to PythonDataclasses with type hints
JSON to C FAQ
Does it generate parsing code for C?
No. C has no standard JSON library, so it generates the data structures. Fill them with cJSON, jansson, json-c or a similar library.
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.