Yo, welcome to SXJSON! This is my own implementation of a JSON handler in C because I felt like it.
It's designed to be super high-level and easy to use, kinda like Python's json module but in C (which makes it 10x cooler).
I'm using my own SXList for dynamic arrays/objects and SXFS for file operations because standard libraries are boring.
- High Level API: Create, modify, and access JSON data without headaches.
- Python-like Syntax:
sxjson_loads,sxjson_dumps, you know the drill. - File System Integration: Load/Save directly to files with
sxjson_loadandsxjson_dump. - Memory Management: Handles memory pretty well, just remember to free the root object.
- No External deps: Only depends on my other libraries included as submodules.
Clone the repo with submodules:
git clone --recursive https://github.com/SwirX/SXJSON.git
cd sxjsonBuild the library and example:
makeRun tests to make sure I didn't break anything:
make testHere is a quick example of how to use it (check examples/main.c for more):
#include "include/sxjson.h"
#include <stdio.h>
int main() {
// creating an object
SXJSON* root = sxjson_object();
sxjson_object_set(root, "name", sxjson_string("SwirX"));
sxjson_object_set(root, "age", sxjson_number(18));
sxjson_object_set(root, "cool", sxjson_bool(true));
// creating an array
SXJSON* list = sxjson_array();
sxjson_array_add(list, sxjson_string("coding"));
sxjson_array_add(list, sxjson_string("sleeping"));
sxjson_object_set(root, "hobbies", list);
// dumping to string
char* str = sxjson_dumps(root);
printf("%s\n", str);
// dumping to file
sxjson_dump(root, "me.json");
// clean up
free(str);
sxjson_free(root);
return 0;
}include/: Header files.src/: Source code.lib/: Submodules (SXList, SXFS).examples/: Example usage.tests/: Unit tests.
Don't break it. If you fix something, cool. open a PR.
MIT or whatever, just give credit.