Questions tagged [nlohmann-json]

Use this tag for questions related to nlohmann JSON C++ library

nlohmann JSON is a header-only JSON class for Modern C++ (C++11)

Latest release: 3.9.1 released on 2020-08-06

See the github project

248 questions
2
votes
0 answers

How to convert nlohmann binary to uint8_t vector?

I get a msgpack object, wrapping an array with uint8_t values from an API and load it to the nlohmann/json library with json::from_msgpack, when I print the json document I get this: { "raw_data": { "bytes": [4, 3, 2, 0, 0, 116, 68], …
Paul Würtz
  • 1,641
  • 3
  • 22
  • 35
2
votes
0 answers

How to pretty print nlohmann::json json file? C++

How can I pretty print my nlohmann::json json file? I have tried o << std::setw(4) << data << std::endl; like an old stackoverflow question said to do, but I get an error saying: main.cpp:39:32: error: no member named 'setw' in namespace 'std' o <<…
JohnJameson
  • 81
  • 1
  • 12
2
votes
1 answer

How to write a vector of structs to json file?

Basically, this question is inverse to this one. I want to write a vector of structs struct Test { std::string Name; std::string Val; }; into a file: [ { "Name": "test", "Val": "test_val" }, { "Name": "test2", "Val":…
Ronaldinho
  • 375
  • 1
  • 12
2
votes
1 answer

How can I `nlohmann::json::get>`?

I've defined the following serializer stack: namespace discordpp { using Snowflake = uint64_t; } namespace nlohmann { template <> struct adl_serializer { static void to_json(json &j, const discordpp::Snowflake sf) { …
Aido
  • 1,524
  • 3
  • 18
  • 41
2
votes
1 answer

Is there a way to serialize a heterogenous vector with nlohmann_json lib?

Hi Stack Overflow Community ! I am working on a project that heavily uses the interesting nlohmann_json library and it appears that I need to add an inheritance link on a specific class, which objects are serialized at one moment. I tried different…
mscherer
  • 97
  • 1
  • 3
  • 12
2
votes
2 answers

nlohmann and copying maps

Anyone has idea how to quickly copy nlohmann::json MAP values to an other nlohmann::json? nlohmann::json j1; nlohmann::json j2; j1["MAP"]["value1"] = 1; j2["MAP"]["value2"] = 2; j2["MAP"] += j1["MAP"]; This will throw because += will think that I…
Grzegorz
  • 3,207
  • 3
  • 20
  • 43
2
votes
1 answer

Error in converting from json using nlohmann json package

I'm trying to convert the json of the form { "content": { "test_key": "test" }, "sender": "alice", "type": "key_type" } to my object which is template struct Event { Content content; std::string…
Bad_Panda
  • 427
  • 1
  • 5
  • 11
2
votes
0 answers

How to merge patch multiple level json with nlohmann library

I have a list of paths like:"blabla/bleble/blibli", "blabla/blibli/bleble" I've succeeded to transform one to this: {"blabla":{"bleble":{"blibli":null}}} with this function: nlohmann::json transform(std::pair aaa){ …
2
votes
1 answer

How to merge same key json data into one in c++ using nlhoman json

I have below JSON data: { "Created": "2019-08-01T14:36:49Z", "Tags": [ { "ObjectId": "1", "Time": 6, "TrackerId": "W1" }, { "ObjectId": "2", "Time": 4, …
S Andrew
  • 5,592
  • 27
  • 115
  • 237
2
votes
2 answers

C++ : using nlohmann json in project

I am trying to use nlohmann json in my C++ project. I extracted the zipped file after I downloaded it from github. I renamed the extracted folder to be nlohmann_json and just copied it inside my project . The github doc says : json.hpp is the…
Istiaque Ahmed
  • 6,072
  • 24
  • 75
  • 141
2
votes
1 answer

Why is json file deleting old inputs from c++?

I need to make a program that stores usernames and passwords. I want to store them in json file. I already made a program that kinda does that, but it deletes old inputs and rewrite them as new. int main() { char pass[12]; char…
2
votes
0 answers

nlohmann json ambiguous overload for 'operator='

I'm getting this compilation error with the following code #include #include #include "nlohmann_json.hpp" namespace nlohmann { template struct adl_serializer> { static void…
SU3
  • 5,064
  • 3
  • 35
  • 66
2
votes
1 answer

Using valijson with Nlohmann's JSON for Modern C++ to validate schemas with subschemas

Can valijson be made to work with Nlohmann's json parser for schemas read from a file with references to subschemas in other files? json mySchemaDoc; if (!valijson::utils::loadDocument("testSchema.json", mySchemaDoc)) { cout << "failed to create…
Jimmy Joe
  • 121
  • 8
2
votes
1 answer

C++ nlohmann/json how to use runtime provided json_pointers to read json values

I am using the json parser Json for Modern C++ (https://github.com/nlohmann/json). I know that I can get the value of a JSON value with a JSON_Pointer: auto v1 = j["/a/b/c"_json_pointer]; But how would I go about getting the value if the JSON…
Ronald Currier
  • 575
  • 1
  • 5
  • 11
1
vote
1 answer

Store std::optional value to json file c++

I have a std::optional test; I want to store this value to json file, and since it is optional, I donot know until runtime, if the variable has a value or not. So I am trying to do this frameJson["Test"] = test.has_value() ? test.value() :…
Nitron_707
  • 307
  • 4
  • 10