Skip to content
Optimized JSON in C
C Makefile
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
doc
src
test
.gitignore
.travis.yml
CHANGELOG.md
LICENSE
Makefile
README.md
notes

README.md

OjC

Build Status

Optimized JSON in C

Description

Optimized JSON in C (OjC), as the name implies, was written to provide optimized JSON handling. It is derived from the underlying C parser in Oj. The intended use is for applications that need the maximum performance when reading large JSON document from a file or socket.

Besides being a true streaming parser OjC produces a structure that handles all JSON constructs. It does not use a Hash or Map to represent the JSON object type but keeps all occurances of a pairs in the object element.

Multiple JSON elements are allowed in a single stream or from a socket. A callback mechanism is provided to return full JSON elements for each entry in a JSON stream.

Simple JSON Parsing Example

include "ojc/ojc.h"

void
sample() {
    char                buf[256];
    ojcVal              val;
    struct _ojcErr      err;
    const char          *json = "[null,true,\"word\",{\"a\":1234}";

    ojc_err_init(&err);
    // no callback
    val = ojc_parse_str(&err, json, 0, 0);
    ojc_fill(&err, val, 0, buf, sizeof(buf));
    if (OJC_OK != err) {
        printf("error: %s\n", err.msg);
        return;
    }
    printf("parsed json '%s'\n", buf);
    ojc_destroy(val);
}

Simple Callback JSON Parsing Example

include "ojc/ojc.h"

static bool
each__callback(ojcVal val, void *ctx) {
    char                buf[64];
    struct _ojcErr      err;

    ojc_err_init(&err);
    ojc_fill(&err, val, 0, buf, sizeof(buf));
    if (OJC_OK != err) {
        printf("error: %s\n", err.msg);
    } else {
        printf("parsed json '%s'\n", buf);
    }
    return true;
}

void
sample() {
    struct _ojcErr      err;
    const char          *json = "{\"a\":111} {\"b\":222} {\"c\":333}";

    ojc_err_init(&err);
    ojc_parse_str(&err, json, each_callback, 0);
    if (OJC_OK != err) {
        printf("error: %s\n", err.msg);
    }
}

Benchmarks

No official benchmarks are available but in informal tests Oj is 30% faster that simdjson.

Documentation

Documentation: http://www.ohler.com/ojc

Source

GitHub repo: https://github.com/ohler55/ojc

Releases

See {file:CHANGELOG.md}

Follow @peterohler on Twitter for announcements and news about the OjC.

You can’t perform that action at this time.