Skip to content

DeadMG/jsonpp

This branch is 1 commit ahead of Rapptz/jsonpp:master.

Folders and files

NameName
Last commit message
Last commit date
Jun 17, 2014
Mar 10, 2015
Dec 28, 2015
Dec 28, 2015
Mar 6, 2015
Jun 17, 2014
Mar 6, 2015
Jun 18, 2014
May 22, 2015
Mar 5, 2015
Jun 29, 2014
Mar 5, 2015
Sep 23, 2014

Repository files navigation

jsonpp

Build Status

jsonpp is a header-only JSON parser and writer that is currently in development. It is a semi-strict parser that throws exceptions for errors.

jsonpp is licensed with the MIT license.

Features

  • Easy to use with a simple API.
  • No special null, array, or object types.
    • json::null is a type alias to std::nullptr_t.
    • json::array is std::vector<json::value>.
    • json::object is std::map<std::string, json::value>.
  • Decently fast.
  • No dependencies, only the standard library and a C++11 compiler.

Documentation

Documentation is an on going process and can be found here. Amongst documentation you can also find examples.

Example usage

Parsing

#include <jsonpp/parser.hpp>
#include <iostream>

int main() {
    json::parser p;
    json::value v;
    try {
        p.parse("[null, \"hello\", 10.0]", v);
        if(v.is<json::array>()) {
            for(auto&& val : v.as<json::array>()) {
                std::cout << val.as<std::string>("stuff");
            }
        }
    }
    catch(const std::exception& e) {
        std::cerr << e.what() << '\n';
    }
}

Output:

stuff hello stuff

Writing

#include <jsonpp/value.hpp>
#include <iostream>

int main() {
    json::value v = { nullptr, "hello", 10 };
    json::object o = {
        { "key", "value" },
        { "key2", 2 },
        { "key3", nullptr }
    };
    json::dump(std::cout, o);
}

Output:

{
    "key": "value",
    "key2": 2,
    "key3": null
}

Quirks and Specification

  • NaN and inf are currently allowed.
  • Comments, e.g. // stuff is planned to be supported in the future.
  • The parser is not destructive.
  • The parser is recursive descent.
  • Numbers are stored in a double just like JSON but v.as<int> and friends work with caution.
  • String is expected to be in UTF-8.
  • Some errors are not caught but effort has been made to catch a lot of errors.

About

C++11 JSON parser and writer

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 78.7%
  • Python 21.3%