Skip to content

ndoolan360/json.h

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json.h

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.

What makes json.h different to other C json libraries?

  • 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 define JSON_IMPLEMENTATION once.
  • Only depends on the C standard library.

Quick Start

Check example.c

$ make
$ ./example-c

Compiler Flags

JSON_STRINGIFY_OBJECTS_AND_ARRAYS

When 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":...}

JSON_RETURN_ARRAYS_WRAPPED_WITH_TOTAL

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":[...]}

Limitations

  • 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

About

A lightweight, single-header C library for extracting values from JSON

Resources

License

Stars

Watchers

Forks

Packages

No packages published