branches: front
Clone
clone: git://shithub.us/sirjofri/rjson gits://shithub.us/sirjofri/rjson
push: hjgit://shithub.us/sirjofri/rjson
Last commit
c4ef9e29
– sirjofri <sirjofri@sirjofri.de>
authored
on 2026/03/07 18:38
adds readme
About
Reflective JSON wrapper library
To convert between structs and json easily.
EXAMPLE
---snip---
#include <json.h>
#include "rjson.h"
typedef struct Vector Vector;
struct Vector {
double x;
double y;
double z;
};
RJSON_BEGIN(RVector_defs)
RJSON_NUMBER(Vector,x)
RJSON_NUMBER(Vector,y)
RJSON_NUMBER(Vector,z)
RJSON_END()
typedef struct Poi Poi;
struct Poi {
char *label;
double priority;
Vector pos;
};
RJSON_BEGIN(RPoi_defs)
RJSON_STRING(Poi,label)
RJSON_NUMBER(Poi,priority)
RJSON_OBJECT(Poi,pos, RVector_defs)
RJSON_END()
/* Rjson* are RVector_defs and RPoi_defs */
/* void-pointers are pointers to the structures in question */
int rjsontostruct(JSON*, Rjson*, void*);
JSON *rstructtojson(void*, Rjson*);
---snap---
See the test/t.c file for a working example.
SUPPORTED TYPES
RJSON_STRING(Struct,Name)
RJSON_NUMBER(Struct,Name)
RJSON_BOOL(Struct,Name)
RJSON_OBJECT(Struct,Name, Subobject_defs)
IMPORTANT
→ char* members are malloc'd strings.
→ the name in the macros mustn't start with a space character.
→ there's currently no array support
→ there should be no leaks
→ there are probably bugs