json11

A tiny JSON library for C++11.

  • Owner: dropbox/json11
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

json11

json11 is a tiny JSON library for C++11, providing JSON parsing and serialization.

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

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

It's easy to make a JSON object with C++11's new initializer syntax:

Json my_json = Json::object {
    { "key1", "value1" },
    { "key2", false },
    { "key3", Json::array { 1, 2, 3 } },
};
std::string json_str = my_json.dump();

There are also implicit constructors that allow standard and user-defined types to be
automatically converted to JSON. For example:

class Point {
public:
    int x;
    int y;
    Point (int x, int y) : x(x), y(y) {}
    Json to_json() const { return Json::array { x, y }; }
};

std::vector<Point> points = { { 1, 2 }, { 10, 20 }, { 100, 200 } };
std::string points_json = Json(points).dump();

JSON values can have their values queried and inspected:

Json json = Json::array { Json::object { { "k", "v" } } };
std::string str = json[0]["k"].string_value();

For more documentation see json11.hpp.

Maintenance note: This repo is stable but no longer actively maintained. No further development
is planned, and no new feature PRs will be merged. Bug fixes may be merged on a volunteer basis.

Main metrics

Overview
Name With Ownerdropbox/json11
Primary LanguageC++
Program languageMakefile (Language Count: 3)
Platform
License:MIT License
所有者活动
Created At2013-09-06 22:08:56
Pushed At2020-03-25 23:27:28
Last Commit At2020-03-25 16:27:27
Release Count1
Last Release Namev1.0.0 (Posted on )
First Release Namev1.0.0 (Posted on )
用户参与
Stargazers Count2.6k
Watchers Count142
Fork Count618
Commits Count117
Has Issues Enabled
Issues Count75
Issue Open Count12
Pull Requests Count37
Pull Requests Open Count8
Pull Requests Close Count27
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private