A lightweight C serialization and deserialization library for working with JSON (and future formats like YAML, TOML, XML, CSV).
- Simple and clean C API
- Create JSON objects, arrays, and values
- Serialize JSON to string
- Parse JSON strings back into structured C memory (planned)
- Lightweight, portable, C23 compatible
- Designed for extensibility (YAML, XML support in the future)
Clone the repository:
git clone https://github.com/LeoriumDev/serdec.gitAdd the following files to your project:
serdec.c
serdec.h
Compile together with your code:
gcc your_code.c serdec.c -o your_program#include <stdio.h>
#include "serdec.h"
int main(void) {
serdec_json_t* root = serdec_json_new_object();
serdec_json_add_string(root, "name", "Leorium");
serdec_json_add_int(root, "age", 20);
serdec_json_t* hobbies = serdec_json_new_array();
serdec_json_array_add(hobbies, serdec_json_new_string("C Programming"));
serdec_json_array_add(hobbies, serdec_json_new_string("Motorcycling"));
serdec_json_add_object(root, "hobbies", hobbies);
char* output = serdec_json_stringify(root);
printf("%s\n", output);
serdec_json_free(root);
free(output);
return EXIT_SUCCESS;
}serdec_json_new_object(void)serdec_json_new_array(void)serdec_json_new_null(void)serdec_json_new_bool(bool value)serdec_json_new_int(int64_t value)serdec_json_new_float(double value)serdec_json_new_string(const char* string)
serdec_json_add_nullserdec_json_add_boolserdec_json_add_intserdec_json_add_floatserdec_json_add_stringserdec_json_add_arrayserdec_json_add_object
char* serdec_json_stringify(const serdec_json_t* object)- (Planned)
char* serdec_json_pretty_stringify(const serdec_json_t* object)
void serdec_json_free(serdec_json_t* node)
This project is licensed under the MIT License.
- JSON serialization
- JSON object and array creation
- Memory-safe node creation
- JSON deserialization (parsing)
- Pretty-printing JSON
- YAML serialization/deserialization
- XML serialization/deserialization
Pull requests are welcome!
For major changes, please open an issue first to discuss what you would like to change.
- Inspired by lightweight C libraries like cJSON and jansson.
- Built from scratch for full control over serialization and future extensibility.