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
0
votes
1 answer

Validating if a JSON object is present in a file with nlohmann JSON C++ library

I have a project where I import JSON files to setup global variables. There are various possibilities to the JSON object names in the files, so I want to know how can I check if an object is there or not. The way I tried to do it (with an if…
JCSB
  • 345
  • 2
  • 16
0
votes
1 answer

C++ version conflict for using nlohmann/json in drake

I recently found out that nlohmann/json runs on C++ 11. Otherwise it gives some syntax error due to a deprecated line from using a higher C++…
Yuki
  • 139
  • 6
0
votes
1 answer

Nlohmann's json library, json array to a vector of structs with pointers inside the struct

I saw this post about converting a json array to a vector of structs. I have a struct named Foo: typedef struct Foo { Foo* SubFoo; } Foo; and when I try to do this: void from_json(const nlohmann::json& j, Foo& f) { …
Ank i zle
  • 2,089
  • 3
  • 14
  • 36
0
votes
1 answer

nlohmann json use the .at() method for a vector of indexes

I have been using the nlohmann json library for a while, but i found myself with a problem recently. I have a vector of indexes for an object: vector indexes = {"value1", "subval"}; // etc and I want to do something like this: json myObj =…
Ank i zle
  • 2,089
  • 3
  • 14
  • 36
0
votes
1 answer

Read Json to object

I am currently trying to read json file into an object. The version of nlohmann-json that I am using is 3.7.3. I followed the example code in that documentation that goes like this // read a JSON file std::ifstream i("file.json"); json j; i >>…
alongtest12
  • 103
  • 1
  • 3
  • 13
0
votes
0 answers

Using nlohmann fifo_map with base class and derived class

I am currently trying to generate JSON with ordered keys and therefore used a workaround method. However, if I try to use it within my base and derived classes, I get an error which I do not really understand. It seems like it fails to call the…
user7335295
  • 401
  • 2
  • 7
  • 31
0
votes
1 answer

create a valid json file using nlohmann::json

I'm trying to create a valid JSON file that looks like that: [ { "id": 1, "price": 0, "qty": 0 }, { "id": 1, "price": 1, "qty": 1 }, { "id": 2, "price": 2, "qty": 2 } ] my current code creates { "id": 1, …
yaodav
  • 1,126
  • 12
  • 34
0
votes
0 answers

Convert a txt file to JSON in C++

I have a C++ program where I jump around between many different files and classes collecting data that I'd like to output as one clean JSON file. I'm using nlohmann's JSON files. I can successfully write to a JSON file by doing the following: json…
Otherness
  • 385
  • 2
  • 16
0
votes
1 answer

JSON to an array of structs in nlohmann json lib

I recently asked this question about converting an array of objects into a vector of structs. I want to do the same thing, but rather vectors I want an array. For example [ { "Name": "Test", "Val": "TestVal" }, { "Name": "Test2", …
Ank i zle
  • 2,089
  • 3
  • 14
  • 36
0
votes
0 answers

Fstream closes after write attempt without errors

I am writing a config for my program. This config is stored in json format using nlohman json. I am using std::fstream to write json object to file. All was fine, but after some moment my program stopped writing to file. Here is a minimal…
0
votes
1 answer

Does .value("key", default) not work with empty json objects?

I've run into a bit of a snag using the value function in the nlohmann/json library. I have an empty json object and I want to either initialize it or increment it if the nested keys are initialized. I've been trying to solve this problem using the…
iHowell
  • 2,263
  • 1
  • 25
  • 49
0
votes
2 answers

std::string can be passed as nlohmann::json to explicit constructor

Why does the following code compile, even though I am passing a std::string object to a explicit constructor which expects a nlohmann::json (to the library) object? My understanding is that std::string won't be implicit converted due to the explicit…
DasElias
  • 569
  • 8
  • 19
0
votes
1 answer

basic trouble making the nlohmann json library work in Visual Studio 19

I'm a neophyte. I know I'm doing something bonheaded. I've search this and other fora for the last day and I'm stuck. I'm trying to use nlohmann's json library. I'm getting over 200 error messages, most of which seem to be rooted in the fact that…
ozindfw
  • 21
  • 5
0
votes
0 answers

Why am I getting invalid UTF8 errors?

I am trying to send a JSON from C++ code to a REST service running on Java. I am using Visaul Studio 2019, nlohmann/json library to serialize my objects and libcurl to make the HTTP request. I have an the following object I want to…
bobku123
  • 81
  • 9
0
votes
1 answer

I'm getting a [json.exception.type_error.302] for some reason in my code. I know what the error means but I don't know where there's a fault

My code goes through the values of each sample in a JSON file and gives out the number of sorting comparisons, the amount of memory, and time it takes for the sorting to happen. But for some reason the code is throwing me an error. Would love it if…
Raunak Anand
  • 47
  • 1
  • 2
  • 8