Help with C++ writing to JSON

Hi, I'm making a game server and my database is in JSON format. However, I would like to know how do I check if a field exist in the .json file and add in the field if it doesn't exist?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "json.hpp"

std::ifstream ifff("players/" + PlayerDB::getProperName(p->rawName) + ".json");
json j;

ifff >> j;

int bac, han, fac, hai, fee, pan, nec, shi, mas, lvl, gem, mut, ban, adl;

bac = j["ClothBack"];
han = j["ClothHand"];
fac = j["ClothFace"];
hai = j["ClothHair"];
fee = j["ClothFeet"];
pan = j["ClothPants"];
nec = j["ClothNeck"];
shi = j["ClothShirt"];
mas = j["ClothMask"];
lvl = j["Level"];
gem = j["Gems"];
mut = j["isMuted"];
ban = j["isBanned"];
adl = j["adminLevel"];

ifff.close();


For example, I want to add in a new field called "SkinColor". How do I check if the field exists or not in the json file and write it in if it doesn't exist? Thanks in advance.
Perhaps you could tell us which particular json.hpp you're referring to.

Generally, one would read any associated manual, readme or examples that come with the download (or webpage).

Or you could just open up json.hpp, work your way through the code to see if you can locate an 'exists' function or method.
I would actually recommend boost PropertyTree. See:

https://www.boost.org/doc/libs/1_69_0/doc/html/property_tree/parsers.html#property_tree.parsers.json_parser

Otherwise, it is of course the question, what this json actually is.
Topic archived. No new replies allowed.