Skip to content

Getting started

Getting started is really easy. First, download the latest release of JasonPP and put these two files in your project folder.

Regardless of your compiler, you'll have to add JasonPP.cpp to your compile list.

g++

g++ main.cpp JasonPP.cpp

Visual Studio

Right-click on your solution in the file hirachy, click on Add->Existing file.

Then just select JasonPP.hpp and JasonPP.cpp and click OK

In-Code setup:

#include "JasonPP.hpp"
using namespace JasonPP;

that's it! Now, test it!

Read json

// Or read it from a file :)
std::string myJsonCode = "{\"age\":17,\"height\":185.4,\"name\":\"Hubert Cumberdale\"}";

Json json;
json.Parse(myJsonCode);

// Now, read some values! :)
int age          = json["age"];
float height     = json["height"];
std::string name = json["name"];
Don't do it

Don't try to get the values of labels that do not exist, and don't try to get the wrong datatype.
This will raise exceptions.
You can always check via

Create json

Now, there are two ways. Inline and procedurally.

Inline:

Json json = JsonBlock({
   Ele("age", 17),
   Ele("height", 185.4f),
   Ele("name", "Hubert Cumberdale"),
});

Procedurally:

Json json = JsonBlock(); // Initialize as empty JsonBlock
json["age"] = 17;
json["height"] = 185.4f;
json["name"] = "Hubert Cumberdale";

Now, just get its json code!

std::string code         = json; // OR
std::string code         = json.Render();
std::string minifiedCode = json.Render(true);

Or just dump it directly to the console!

std::cout << json << std::endl;