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
1
vote
0 answers

trying to include nlohmann/json.hpp

OS environment is Centos 8 g++ version 8.5 and for Ubuntu 22.0 g++ 11.3.0 I have a nagging issue, which doesn't rear its head when I build on Ubuntu. I'm finding that for my centos build in order for the the compiler to find the 'json.hpp' I have to…
1
vote
0 answers

json nlohmann converting json to structure with char* types

I have the following code which works fine with a basic stucture containing an int and std::string types. I have made a custom helper to convert the raw json to my structure type. #include #include #include…
user2020
  • 217
  • 2
  • 12
1
vote
1 answer

when running a function from my project, the stod() function gives an incorrect result

I have three files - a json file, my project, and test (main.cpp) json file: { "points": { "range": 25, "step": 0.001 } } in file main.cpp this code: #include #include #include #include…
frnzzz
  • 11
  • 2
1
vote
1 answer

OvenMediaEngine Answer Sdp parsing error: a=group:LS locQqN

I cannot connect to OvenMediaEngine server with a libdatachannel library. When I send answer message it returns Could not parse SDP error. I can't find true format of answer type message. I sent request offer with: {"command",…
1
vote
1 answer

How to get the data after parsing json created using nlohmann json

I have a requirement to store two structure namely one and two in Json in following format, and then parse this JSON and store the data back to those structure object. { "One",{ { "Value1", one.Value1() }, } }, { "Two",{ …
1
vote
1 answer

access array using 'nlohmann' JSON parser

I am trying to access an JSON array using 'nlohmann' library, as the example below shows: #include #include #include "json.hpp" using json = nlohmann::json; int main() { { const std::string str( R"( { …
canellas
  • 491
  • 5
  • 17
1
vote
1 answer

user writes access path to a nested element in a JSON file

I wrote a code that prompts the user for the access path to an element in a JSON file and then retrieves the value of that element. But I can only get access to a root element. What should user write to e.g. get object.array[2].field? I use single…
Plateau
  • 13
  • 3
1
vote
1 answer

JSON output differs between gcc and MSVC

The below code snippet is using nlohmann-json library. However the output differs between MSVC and GCC compilers (both compiled using -std=c++14). MSVC outputs: {"test":[]} gcc outputs: {"test":[[]]} Code snippet: #include…
Constantin
  • 8,721
  • 13
  • 75
  • 126
1
vote
1 answer

C++ Json parsing issue throws Unhandled Exception

`` I am trying to order a vector of coins to be traded in order of their market cap rank. it compiles perfectly and runs but throws an error 3 at runtime. code found below. debugging: json.hpp Throws unhandled exception Unhandled exception at…
John Doe
  • 47
  • 6
1
vote
1 answer

Iterate using iterators on nlohmann::json? Error: invalid_iterator

Continuing my previous question here, Now I want to insert the keys and values present in the below json into a std::vector>> vec; Keys here are this strings: 12CUDzb3oe8RBQ4tYGqsuPsCbsVE4KWfktXRihXf8Ggq…
1
vote
0 answers

Translate nlohmann into json to torch tensor

I have this code with specific hard-coded dimension and dimensionality auto x_data=json_data.at("x").get>>(); auto x_options = torch::TensorOptions().dtype(at::kFloat); torch::Tensor x_tensor =…
Fzza
  • 105
  • 1
  • 9
1
vote
1 answer

Parse error in valid JSON data with nlohmann's C++ library

i have the following JSON data in a .json file: [ { "Type":"SET", "routine":[ { "ID":"1", "InternalType":"Motorcycle", "payload":"2" }, { "ID":"12", …
schande
  • 576
  • 12
  • 27
1
vote
2 answers

STD flexible data structure? c++

I'm using nlohmann json objects, since they can add key-value pairs after runtime (and can readily be serialized)... Though I realize this may sacrifice speed. Are there any data structures, of similar flexibility, that are from standard c++…
1
vote
1 answer

Why is this map returning an rvalue?

I am using the library nlohmann/json and wish to create an unordered_map of std::string to nlohmann::json. #include class basic_container { public: using key_type = std::string; using mapped_type = nlohmann::json; …
Jaan
  • 330
  • 2
  • 9
1
vote
1 answer

Hidden friend to_json function unexpectedly resolves for shared_ptr

The code below (Goldbolt) compiles and runs (on both gcc and clang) and does what I would hope. But I'm surprised! I expected to have to use an adl_serializer specialisation (as opposed to the hidden friend here) for it to be able to find the…
tp288843
  • 13
  • 2