A JSON schema code generator for C
Find a file
Simon Ser 7e126808c8
All checks were successful
builds.sr.ht Job completed
ci: add .build.yml
2025-12-13 11:42:41 +01:00
example Rename main.c to tool.c 2022-11-18 16:02:11 +01:00
include encoding: add link to RFC 2022-11-21 21:36:52 +01:00
test test: add jsch_raw_value test 2025-12-12 19:47:04 +01:00
tool tool: fix gen-code for unspecified arrays/objects 2025-12-12 22:41:13 +01:00
.build.yml ci: add .build.yml 2025-12-13 11:42:41 +01:00
decoder.c decoder: limit max nesting depth 2022-11-21 21:42:30 +01:00
encoder.c encoder: handle NULL in jsch_encode_raw_value() 2022-11-20 19:35:29 +01:00
LICENSE Initial commit 2022-11-10 11:45:57 +01:00
meson.build Add basic decode test 2025-12-09 00:53:10 +01:00
meta.c meta: decode "not" 2025-12-12 21:30:07 +01:00
README.md Move to Codeberg 2025-03-25 21:41:36 +01:00

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 properties set and additionalProperties set to false: each JSON field generates one C field.
  • For objects with properties unset and additionalProperties set: keys, values and len fields are generated containing arrays for the keys/values and the number of entries.
  • For arrays with items set: data and len fields 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 by maximum and minimum, otherwise int is used.
  • For booleans, strings, numbers: the native C types bool, char *, double are used.
  • For anything else: struct jsch_raw_value is generated to delay decoding.

License

MIT