A lightweight, single-header C library for extracting values from JSON strings using simple path syntax (e.g., "user.profile.name" or "items.0.price").
Inspired by bztsrc/jsonc
Warning
This library is in early development and the API may change.
- Extract only the values you need without building a full DOM tree.
- Use dot notation to navigate nested objects and arrays.
- Perfect for extracting a few values from large JSON responses without overhead.
- Just
#include "json.h"and defineJSON_IMPLEMENTATIONonce. - Only depends on the C standard library.
Check example.c
$ make
$ ./example-cWhen set to 1, returns objects and arrays as JSON strings instead of NULL.
// Default (0): returns NULL for objects/arrays
char *data = json_get(json, "spacecraft");
// output: NULL
// With flag (1): returns object as though it's a string literal
char *data = json_get(json, "spacecraft");
// output: {"name":"Orion MPCV" "manufacturer":...}When set to 1 (default), wraps array results with total count.
This has no effect when JSON_STRINGIFY_OBJECTS_AND_ARRAYS is 0.
// Disabled (0): returns raw array
char *crew = json_get(json, "crew");
// output: [...]
// Default (1): wraps with total
char *crew = json_get(json, "crew");
// output: {"total":4,"items":[...]}- Not RFC 8259 compliant - designed for practical use cases, not strict JSON compliance
- String escaping within JSON strings is not currently supported
- Key names containing dots (
.) are not supported - This library is designed for value extraction, not JSON manipulation or creation