C to JSON Converter

Paste C structs or initializers. Get clean JSON back.

Input

Output

Paste your C code on the left and press Convert.

Or drop a file on this box, , or .

What this tool does

Embedded and systems work keeps producing the same chore: a JSON body that has to match a C struct, for a test against a gcc-built service, a device provisioning file or a protocol document. The usual route is linking cJSON and writing one cJSON_Add... call per member. Here you paste the typedefs plus an initializer, and the backend sends back the JSON form of that value, nested structs and fixed-size arrays included, with no Makefile in sight.

The converter understands how C values actually serialize. int, long, size_t, float, and double all become JSON numbers. char arrays and string literals become JSON strings. bool from stdbool.h becomes true/false. Fixed arrays (int items[3]) become JSON arrays with the right length. Nested structs (an Address inside an Order, say) expand into nested JSON objects. The behaviour tracks the C language reference.

C99 designated initializers (.field = value) are fully supported, which is the usual way you see real-world struct literals written today. typedef aliases are resolved, and enum values come out as either their numeric value or the symbol name depending on context. Union types serialize the active member. Pointer members to NULL become JSON null; otherwise the pointed-to value is expanded. Paste multiple structs at once and each one becomes a top-level key in the output.

How to use it

Three steps. Works the same for a two-line initializer as it does for a full header with twenty typedefs.

1

Paste your C (or load the sample)

Paste the header or .c fragment on the left: typedef struct blocks, a designated initializer such as Order order = { .order_id = "ORD-4821", ... }, or several structs that reference each other. Load Sample fills the editor with an Order that holds two OrderItem entries and an Address, written with stdbool.h and C99 initializers.

You do not need to remove #include directives or compiler-specific attributes. Leave the ISO C syntax intact: the parser handles it. Both C89 and modern (C11/C17/C23) are fine.

2

Hit Convert

Press the green Convert button. The code goes to the backend, which reads char[] members as strings and bool as true/false, then hands back JSON while a "Converting..." overlay sits over both panels.

3

Copy the JSON

The right panel is read-only and has no copy button, so click into it, select all and copy. If the backend could not produce valid JSON from your C, that panel shows the error followed by the raw reply, which is often one bracket away from usable.

When this actually comes in handy

Embedded config & firmware

You have a device config struct in C and need a JSON version for a REST endpoint or provisioning tool. Paste the struct, grab the JSON, ship it.

API request payloads

A C service wrapping a third-party API. Paste the request struct, get JSON you can test with curl before wiring up cJSON in production.

Unit test fixtures

Your Unity or CMocka tests already build structs with designated initializers. Convert one of those and save the result as a golden file that an integration suite or a Python harness can load.

Docs that match the code

Generate JSON examples for a README or protocol doc straight from your real structs, so the docs stay in sync with the header file.

Common questions

Do I need cJSON or Jansson installed?

No library at all. Nothing is compiled or linked; the backend reads the source text and replies with JSON. When you later need the same thing at runtime on the device, cJSON is a single C file that drops into embedded builds, and Jansson has a friendlier API on Linux.

Does it understand designated initializers and typedefs?

Yes. C99 designated initializers (.field = value) are fully supported, and typedef aliases are resolved back to their underlying struct. Nested designated initializers expand the same way a compiler would lay them out.

What about arrays, pointers, and NULL?

Fixed-size arrays become JSON arrays with the right element count. Pointer members that are NULL become JSON null; otherwise the pointed-to value is expanded. Arrays of structs work the same way: each element is a nested JSON object.

How are enums and unions handled?

enum values come out either as the symbol name or the numeric value depending on context. union types serialize the currently active member. Bitfields (unsigned flags : 4) become numbers.

Is my code stored?

It is posted to the backend only to do the conversion and is not kept afterwards. Firmware sources often carry Wi-Fi passwords, API keys or calibration secrets in #defines, so blank those out before you paste.

What if the C has macros or compiler extensions?

Macros that expand to a value work; function-like macros that do real logic are treated as opaque and emitted as null rather than halting. GCC and MSVC attributes (__attribute__, __declspec) are tolerated and ignored.

Other tools you may need

If your codebase mixes C with its C-family neighbours, or the JSON deserves a second look, try these next: