Giter VIP home page Giter VIP logo

minijson's Introduction

MiniJson

Language Standard

JSON is a lightweight data-interchange format. It can represent numbers, strings, ordered sequences of values, and collections of name/value pairs.

MiniJson is a tiny JSON library that allows manipulating JSON values, including serialization and deserialization to and from strings.

MiniJson is written in C++17 and test the code using the GoogleTest framework.The classes are heavily unit-tested and covers 100% of the code, including all exceptional behavior.


The core object provided by the library is MiniJson::Json. A Json object represents any JSON value: null(nullptr_t), bool, number (int or double), string(std::string), array(std::vector), or object (std::unordered_map).

Json objects act like values. They can be assigned, copied, moved, compared for equality and so on. There are also helper methods Json::serialize, to serialize a Json to a string, and Json::parse (static) to parse a std::string or const char* as a Json object.


We can construct a JSON object very intuitively:

Json my_json1(nullptr);
Json my_json2 = "string";

Json my_json3 = Json::_object {
    { "key1", "value1" },
    { "key2", false },
    { "key3", Json::_array { 1, 2, 3 } },
};

String can be expressed explicitly using Json::parse() easily:

string errMsg;// store error messages when catch a exception in parse process
auto js = Json::parse("[ null , false , true , 123 , \"abc\" ]",errmsg);
cout << js[4] << endl;

You can also get a string representation of a JSON value (serialize):

auto str = js.serialize();

Even you can try to output the JSON object directly:

cout << js << endl;

This work is inspired by https://github.com/miloyip/json-tutorial and https://github.com/Yuan-Hang/Json.

More documentation is still to come. For now, please see Json.h.

minijson's People

Contributors

zsmj2017 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.