Ujson
No description available
Install / Use
/learn @metan-ucw/UjsonREADME
UJSON
UJSON is:
- Complete and simple JSON reader and writer written in C
- Produces nice and human readable error messages
- Passes JSONTestSuite
See generated documentation at: https://metan-ucw.github.io/ujson/files.html
The key point of this parser is that:
- works on a buffer in a memory that is not modified during the parsing
- parser does not allocate memory
- nearly stateless, the only state the parser maintains is an offset to the string buffer, recursion depth and error flag
- if error flag is raised all parser functions return immediatelly with error
The parser is started by a call to ujson_start() function in order to
determine if first element in the buffer is object or an array.
switch (ujson_reader_start(reader)) {
case UJSON_ARR:
//parse array
break;
case UJSON_OBJ:
//parse object
break;
default:
break;
}
if (ujson_reader_err(reader))
ujson_err_print(reader);
Then you can loop recursively over arrays and objects with:
char sbuf[128];
struct ujson_val json = {.buf = sbuf, .buf_size = sizeof(sbuf)};
UJSON_OBJ_FOREACH(reader, &json) {
switch (json.type) {
case UJSON_OBJ:
//parse object
break;
case UJSON_ARR:
//parse array
break;
case UJSON_STR:
...
}
}
The supported types are:
- UJSON_ARR - an array, needs to be parsed recursivelly
- UJSON_OBJ - an object, needs to be parsed recursivelly
- UJSON_INT - an integer number stored as val_int (also sets val_float for convinience)
- UJSON_FLOAT - a floating point number stored as val_float
- UJSON_BOOL - a boolean stored as val_bool
- UJSON_NULL - a null has no value
- UJSON_STR - a string, stored in user supplied buffer
Related Skills
node-connect
340.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
340.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.1kCommit, push, and open a PR
