GithubHelp home page GithubHelp logo

tempbottle / jsonpp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rapptz/jsonpp

0.0 2.0 0.0 550 KB

C++11 JSON parser and writer

Home Page: http://rapptz.github.io/jsonpp/

License: MIT License

Python 21.96% C++ 78.04%

jsonpp's Introduction

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.

jsonpp's People

Contributors

cocophotos avatar rapptz avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.