cojson - a JSON parser for constrained platforms

27 Oct 2015

Dear Community,

Please let me share with you a C++ library for parsing/generating JSON.

Project overview: http://hutorny.in.ua/projects/cojson-a-json-parser-for-constrained-platforms

cojson tutorial: http://hutorny.in.ua/projects/cojson-tutorial

Library sources: https:/github.com/hutorny/cojson

mbed example: https://raw.githubusercontent.com/hutorny/cojson/master/examples/json_via_mbed_stream.cpp

Status on mbed platform: buildable with arm-none-eabi-g++

Example of using cojson

#include "cojson.hpp"
using namespace cojson;
#define NAME(s) static inline constexpr const char* s() noexcept { return #s; }
class Pdo {
    struct Name {
        NAME(u)
        NAME(s)
        NAME(v)
    };
    char s[16];
    short u;
    short v; 
    // JSON structure definition
    static const clas<Pdo>& structure() {
        return
            O<Pdo,
                P<Pdo, Name::s, countof(&Pdo::s), &Pdo::s>,
                P<Pdo, Name::u, decltype(Pdo::u), &Pdo::u>,
                P<Pdo, Name::v, decltype(Pdo::v), &Pdo::v>
    >();
    }
public:
    // reading JSON
    inline bool read(lexer& in) { return structure().read(*this,in); }
    // writing JSON
    inline bool write(ostream& out) { return structure().write(*this,out); }
};