JSON to C Converter
Generate C struct definitions from a JSON sample, including the length fields that arrays in C always need.
Your data stays on your device
Input — JSON
- characters
- 0
- lines
- 0
- size
- 0 B
Output — C
- characters
- 0
- lines
- 0
- size
- 0 B
Options
About this tool
C has no dynamic arrays and no string type, so a JSON array becomes a pointer plus a separate count field, and a string becomes a char pointer. Those conventions are what make the difference between a struct you can actually use and one you have to rewrite.
The generator emits typedefs for every struct, orders declarations so dependencies come first, and pairs each array field with a size_t count. Memory management remains yours: the output describes the shape, not the lifecycle.
How to use this tool
- Paste your JSON sample.
- Set the root struct name.
- Choose the integer width and whether to emit typedefs.
- Press Generate and copy the declarations into a header.
Key features
- typedef struct declarations with a conventional _t suffix option
- char * for strings and bool for booleans, with stdbool.h noted
- Every array emitted as a pointer plus a size_t count field
- Configurable integer width: int, long or int64_t
- Nested structs ordered so the header compiles top to bottom
- C keywords and invalid identifiers renamed safely
Example
Input — JSON
{"name":"node","ports":[80,443]}Output — C
typedef struct Root {
char *name;
int *ports;
size_t ports_count;
} Root;Good to know
- No parsing or serialisation code is generated. You will need a library such as cJSON or jansson to populate these structs.
- Allocation and freeing are not handled; the structs describe layout only.
- C has no optional type, so absent values are represented by NULL pointers or by a sentinel you choose.
Frequently asked questions
Why does every array have a count field?
Because a C pointer carries no length. Without an explicit count there is no safe way to iterate the array.
Which JSON library pairs well with this?
cJSON is small, permissively licensed and easy to embed. jansson is a good alternative with a slightly richer API.
How are nested objects represented?
As a member of the nested struct type by value, or as a pointer if you enable pointer members for nested structs.
How do I represent a missing value?
A NULL pointer for strings, arrays and nested pointers. For scalars you need a separate presence flag or an agreed sentinel value.
Your data stays on your device
Your data is processed locally in your browser and is not uploaded to our server. This page keeps working after you go offline, because there is nothing to send.