All Projects → tsoding → jim

tsoding / jim

Licence: MIT license
Immediate Mode JSON Serialization Library in C

Programming Languages

c
50402 projects - #5 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to jim

iris
Lightweight Component Model and Messaging Framework based on ØMQ
Stars: ✭ 50 (+42.86%)
Mutual labels:  serialization
serialization-parcelable
Android Parcelable support for the Kotlinx Serialization library.
Stars: ✭ 53 (+51.43%)
Mutual labels:  serialization
php-serializer
Serialize PHP variables, including objects, in any format. Support to unserialize it too.
Stars: ✭ 47 (+34.29%)
Mutual labels:  serialization
FlexBuffersSwift
Swift implementation of FlexBuffers - a sub project of FlatBuffers
Stars: ✭ 24 (-31.43%)
Mutual labels:  serialization
avro-serde-php
Avro Serialisation/Deserialisation (SerDe) library for PHP 7.3+ & 8.0 with a Symfony Serializer integration
Stars: ✭ 43 (+22.86%)
Mutual labels:  serialization
sqlathanor
Serialization / De-serialization support for the SQLAlchemy Declarative ORM
Stars: ✭ 105 (+200%)
Mutual labels:  serialization
roswasm suite
Libraries for compiling C++ ROS nodes to Webassembly using Emscripten
Stars: ✭ 62 (+77.14%)
Mutual labels:  serialization
Eden
edn (extensible data notation) encoder/decoder for Elixir
Stars: ✭ 32 (-8.57%)
Mutual labels:  serialization
ZFFramework
cross-platform C++ application framework, do 80% work at 20% cost
Stars: ✭ 65 (+85.71%)
Mutual labels:  serialization
gradle-flatbuffers-plugin
Gradle plugin for generating code from Google FlatBuffers schemas
Stars: ✭ 20 (-42.86%)
Mutual labels:  serialization
SafeParcel
Helper library and format description for SafeParcel, a version-agnostic parcelable serializer
Stars: ✭ 29 (-17.14%)
Mutual labels:  serialization
pony-capnp
Cap’n Proto plugin for generating serializable Pony classes. 🐴 - 🎩'n 🅿️
Stars: ✭ 19 (-45.71%)
Mutual labels:  serialization
zkar
ZKar is a Java serialization protocol analysis tool implement in Go.
Stars: ✭ 435 (+1142.86%)
Mutual labels:  serialization
dubbo-hessian-lite
Hessian Lite for Apache Dubbo
Stars: ✭ 45 (+28.57%)
Mutual labels:  serialization
yserial
NoSQL y_serial Python module – warehouse compressed objects with SQLite
Stars: ✭ 17 (-51.43%)
Mutual labels:  serialization
pidi-os
A minimalistic operating system
Stars: ✭ 35 (+0%)
Mutual labels:  pure-c
Bytes
Swift Library for working with sequences of Bytes (aka [UInt8])
Stars: ✭ 35 (+0%)
Mutual labels:  serialization
har-rs
A HTTP Archive format (HAR) serialization & deserialization library, written in Rust.
Stars: ✭ 25 (-28.57%)
Mutual labels:  serialization
jsonapi-serializable
Conveniently build and efficiently render JSON API resources.
Stars: ✭ 43 (+22.86%)
Mutual labels:  serialization
marshmallow-validators
Use 3rd-party validators (e.g. from WTForms and colander) with marshmallow
Stars: ✭ 24 (-31.43%)
Mutual labels:  serialization

JIM

Immediate Mode JSON Serialization Library in C. Similar to imgui but for generating JSON.

Example

example.c:

#include <stdio.h>

#define JIM_IMPLEMENTATION
#include "./jim.h"

int main()
{
    Jim jim = {
        .sink = stdout,
        .write = (Jim_Write) fwrite,
    };

    jim_object_begin(&jim);
        jim_member_key(&jim, "null");
        jim_null(&jim);

        jim_member_key(&jim, "bool");
        jim_array_begin(&jim);
            jim_bool(&jim, 0);
            jim_bool(&jim, 1);
        jim_array_end(&jim);

        jim_member_key(&jim, "integers");
        jim_array_begin(&jim);
            for (int i = -3; i <= 3; ++i) {
                jim_integer(&jim, i);
            }
        jim_array_end(&jim);

        jim_member_key(&jim, "floats");
        jim_array_begin(&jim);
            jim_float(&jim, 0.0, 4);
            jim_float(&jim, -0.0, 4);
            jim_float(&jim, 3.1415, 4);
            jim_float(&jim, 2.71828, 5);
            jim_float(&jim, 1.6180, 4);
            jim_float(&jim, 0.0 / 0.0, 4);
            jim_float(&jim, 1.0 / 0.0, 4);
            jim_float(&jim, -1.0 / 0.0, 4);
        jim_array_end(&jim);

        jim_member_key(&jim, "string");
        jim_array_begin(&jim);
            jim_string(&jim, "Hello\tWorld\n");
            jim_string_sized(&jim, "\0\0\0\0", 4);
        jim_array_end(&jim);
    jim_object_end(&jim);

    if (jim.error != JIM_OK) {
        fprintf(stderr, "ERROR: could not serialize json properly: %s\n",
                jim_error_string(jim.error));
        return -1;
    }

    return 0;
}

Output

$ cc -o example example.c
$ ./example | jq .
{
  "null": null,
  "bool": [
    false,
    true
  ],
  "integers": [
    -3,
    -2,
    -1,
    0,
    1,
    2,
    3
  ],
  "floats": [
    3.1415,
    2.71828,
    1.618
  ],
  "string": [
    "Hello\tWorld\n",
    "\u0000\u0000\u0000\u0000"
  ]
}

Testing

$ make
$ ./test

The expected outputs of the test cases are stored in ./test_expected.h. To regenerate it just run:

$ ./test record

Notes

  1. Does not depends on libc. Could be theoretically used in embedded, but I know nothing about embedded, so maybe not.
  2. jim_float() is quite likely very stupid and imprecise
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].