A JSON schema code generator for C
|
|
||
|---|---|---|
| example | ||
| include | ||
| test | ||
| tool | ||
| .build.yml | ||
| decoder.c | ||
| encoder.c | ||
| LICENSE | ||
| meson.build | ||
| meta.c | ||
| README.md | ||
libjsonschema
A JSON schema code generator for C.
Check out the example to get started.
Usage
Generate C code from a JSON schema:
libjsonschema gen-header schema.json >schema.h
libjsonschema gen-code schema.json >schema.c
libjsonschema will generate one struct per object/array in $defs. Each
struct comes with 3 functions: foo_encode() to encode JSON, foo_decode()
to decode JSON and foo_finish() to release the struct after decoding.
The struct contains different fields depending on the type:
- For objects with
propertiesset andadditionalPropertiesset tofalse: each JSON field generates one C field. - For objects with
propertiesunset andadditionalPropertiesset:keys,valuesandlenfields are generated containing arrays for the keys/values and the number of entries. - For arrays with
itemsset:dataandlenfields are generated containing an array of values and the number of entries. - For integers: the native C sized types from
<stdint.h>are used when matched bymaximumandminimum, otherwiseintis used. - For booleans, strings, numbers: the native C types
bool,char *,doubleare used. - For anything else:
struct jsch_raw_valueis generated to delay decoding.
License
MIT