Skip to content

SwirX/SXJSON

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SXJSON - A High-Level JSON Library for C

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.

Features

  • 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_load and sxjson_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.

Installation

Clone the repo with submodules:

git clone --recursive https://github.com/SwirX/SXJSON.git
cd sxjson

Build the library and example:

make

Run tests to make sure I didn't break anything:

make test

Usage

Here 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;
}

Structure

  • include/: Header files.
  • src/: Source code.
  • lib/: Submodules (SXList, SXFS).
  • examples/: Example usage.
  • tests/: Unit tests.

Contributing

Don't break it. If you fix something, cool. open a PR.

License

MIT or whatever, just give credit.

About

A High-Level JSON library for C

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published