Optimized JSON in C
C Makefile
Switch branches/tags
Nothing to show
Clone or download
Latest commit 4e86c67 Feb 11, 2018
Permalink
Failed to load latest commit information.
doc Updated docs for 3.1.1 Nov 19, 2017
src Change -Og option to -O0 Feb 11, 2018
test changed test path Feb 11, 2018
.gitignore Docs (#3) Nov 13, 2017
.travis.yml getting travis to work Feb 11, 2018
CHANGELOG.md Updated docs for 3.1.1 Nov 19, 2017
LICENSE Initial commit May 22, 2014
Makefile added to level makefile Oct 13, 2015
README.md Wire (#1) Nov 9, 2017
notes Wire (#1) Nov 9, 2017

README.md

OjC

Optimized JSON in C

Description

Optimized JSON in C (OjC), as the name implies, was written to provide speed 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. Duplicates are allowed just as they are in JSON documents.

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

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.