CToon is a high-performance, zero-dependency C99 library for reading and writing the TOON serialization format, with built-in JSON interop. This reference documents the plain C API declared in ctoon.h.
Installation
# CMakeLists.txt
include(FetchContent)
FetchContent_Declare(
ctoon
GIT_REPOSITORY https://github.com/MohammadRaziei/ctoon.git
GIT_TAG main
)
FetchContent_MakeAvailable(ctoon)
# Link the C target
target_link_libraries(my_app PRIVATE ctoon::ctoon)
Requires CMake 3.19+ and a C99-compatible compiler.
Quick example
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
const char *src = "name: Alice\nage: 30";
size_t len;
free(toon);
printf("%s\n", json);
free(json);
return 0;
}
static ctoon_val * ctoon_doc_get_root(ctoon_doc *doc)
char * ctoon_doc_to_json(const ctoon_doc *doc, int indent, ctoon_write_flag flags, const ctoon_alc *alc, size_t *len, ctoon_write_err *err)
static ctoon_doc * ctoon_read(const char *dat, size_t len, ctoon_read_flag flg)
static char * ctoon_write(const ctoon_doc *doc, size_t *len)
static const ctoon_write_flag CTOON_WRITE_NOFLAG
static ctoon_val * ctoon_obj_get(ctoon_val *obj, const char *key)
static void ctoon_doc_free(ctoon_doc *doc)
static const char * ctoon_get_str(ctoon_val *val)
See ctoon.h for the full function reference — document I/O (ctoon_read, ctoon_write), the object/array accessors (ctoon_obj_get, ctoon_arr_get, ...), and JSON interop (ctoon_doc_to_json).