Skip to content

📂 A header-only C++17 library for easy JSON integration in modern C++ applications.

License

Notifications You must be signed in to change notification settings

BayernMuller/cpp-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cpp-json

Header-only JSON library for C++17

Introduction

  • cpp-json is a code library for handling JSON in C++ applications, requiring C++17 or higher.
  • To use, simply include the cppjson.h header file in your project.
  • The library offers features for creating, managing, saving, and loading JSON data, as well as converting between JSON and strings.

Installation

Requirements
  • CMake
  • Compiler with C++17 support
    • GCC 7.3 or later
    • Clang 5.0 or later
    • MSVC 19.14 or later
Build
  • Run the following commands to build cpp-json.
    • mkdir build && cd build
    • cmake ..
    • make
    • sudo make install
Run example code
  • After building the library, build directory will contain an example executable.
    • ./example_main

Usage

Creating JSON
#include <cppjson.h>
using namespace json;

Json json
{
	{"best_club", "FC Bayern"},
	{"best_players", Array{"Manuel Neuer", "Thomas Müller"}},
	{"best_coach", Object{{"name", "Hansi Flick"}, {"age", 56}}}
};
Accessing JSON
auto club = json["best_club"];
auto player = json["best_players"][0];
auto coach = json["best_coach"]["name"];
Modifying JSON
json["best_coach"]["name"] = "Jupp Heynckes";
json["best_coach"]["age"] = 75;
json["best_players"].GetValue<Array>().push_back("Joshua Kimmich");
Converting string to JSON
std::string json_str = R"(
{
    "best_club": "FC Bayern"
}
)";
Json json = Utility::Parse(json_str);
std::cout << json["best_club"] << std::endl;

License

  • cpp-json is licensed under the MIT License.

Contributing

  • Contributions are welcome! Please feel free to submit a Pull Request.

About

📂 A header-only C++17 library for easy JSON integration in modern C++ applications.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published