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

Why can't I use the [] operator to access an array in nlohmann's C++ JSON library?

I'm using this JSON library for C++ in order to get information from Twitter's API, which returns a JSON array to my program (that I'm storing in responseData). But when I try to access "name" in the returned array, it doesn't allow me to. Here is…
Gary S
  • 313
  • 1
  • 4
  • 9
5
votes
1 answer

reading arrays of json objects with nlohmann c++ library

I am ok using this syntax with the nlohmann library { "key1": {"subKey1": "value11", "subKey2": "value12"}, "key2": {"subKey1": "value21", "subKey2": "value22"} } But I have a new file, which is valid json too (I checked)…
JCSB
  • 345
  • 2
  • 16
4
votes
3 answers

How to get number as std::string through nlohmann::json parsing?

#include #include #include #include using json = nlohmann::json; int main() { std::cout.precision(std::numeric_limits::max_digits10); // create a JSON value with different types …
q0987
  • 34,938
  • 69
  • 242
  • 387
4
votes
2 answers

building a nested JSON

Some data files that I need to read / parse have headers in the style: level0var = value0 level0var.level1field = value1 level0var.level1array[11].level2field = value2 ... In other words, they look like nested C-style structs and arrays, but none…
alle_meije
  • 2,424
  • 1
  • 19
  • 40
4
votes
0 answers

nlohmann json: securely erase the keys (C++)

I'm using nlohmann/json library to represent sensitive information. Once the needed processing has been completed, I'm interested in securely erasing the keys of the json type. Example: json test; test["key1"] = "value1"; test["key2"] =…
Richard Topchii
  • 7,075
  • 8
  • 48
  • 115
4
votes
3 answers

Can't get_to vector of object inside itself with Nlohmann's JSON

I've got the following code (simplified): namespace nlohmann { // https://github.com/nlohmann/json/issues/1749#issuecomment-772996219 template void to_json(nlohmann::json &j, const std::optional &v) { if (v.has_value()) j =…
Aido
  • 1,524
  • 3
  • 18
  • 41
4
votes
1 answer

How to erase item inside of item in nlohmann::json file C++

I want to know how I can delete an item within an item in the nlohmann::json C++ library. Json example file: { "Users":{ "User1":{ "Name":"BOB", "DeleteMe":"IWantToBeDeleted!" } } } What I want to…
Piboy314
  • 186
  • 1
  • 15
4
votes
2 answers

Is there a better way to handle exceptions ? try-catch block is really ugly

I read this and find out it's important to handle exceptions, i use nlohmann::json (from github) and nearly in most of my member functions is use nlohmann::json::parse and nlohmann::json::dump which make a chance to throw exceptions if the input has…
Kate
  • 561
  • 4
  • 11
4
votes
1 answer

How to configure the cmake file correctly to build a simple hello world for nlohmann_json?

I am using the following JSON parser: https://github.com/nlohmann/json Following is the steps I followed to build : 2074 git clone https://github.com/nlohmann/json.git 2075 git branch 2076 ls 2077 cd json/ 2078 git branch 2079 git pull …
4
votes
1 answer

access json array values in c++

I'm new to c++ and trying to use nlohmann library and I'm quite stuck. I want to modify array of objects from json. json = { "a": "xxxx", "b": [{ "c": "aaa", "d": [{ "e": "yyy" }, { …
Amy
  • 69
  • 2
  • 9
4
votes
1 answer

Bizarre behavior when comparing enum class values

I was working on some JSON parsing code using the lovely nlohmann::json, and to help make useful error messages, I made myself a function to print the type of a JSON object. This function accepts a json::value_t, which is an enum class defined…
alter_igel
  • 6,899
  • 3
  • 21
  • 40
4
votes
1 answer

creating nested json object in c++ using nlohmann json

I am working with https://github.com/nlohmann/json and it works well. However I am finding difficulties to create the following json outout { "Id": 1, "Child": [ { "Id": 2 }, { "Id": 3, …
cateof
  • 6,608
  • 25
  • 79
  • 153
4
votes
1 answer

C++ - Convert JSON or array from it into vector

I'm using https://github.com/nlohmann/json to load JSON file into my program. At this moment, I'm loading it: json jsonFile; ifstream ifs("data/test.json"); ifs >> jsonFile; // create JSON from stream json j_complete(jsonFile); And I have access…
Vertisan
  • 720
  • 3
  • 14
  • 34
3
votes
1 answer

When deserializing a struct with from_json: error: no matching function for call to nlohmann::basic_json<>::get

I'm using the nlohmann/json library and trying to implement serialization and deserialization for one of my structs. I'm going by this example. This is the struct and the relevant types: typedef std::uint32_t vertex_key; typedef std::uint64_t…
corazza
  • 31,222
  • 37
  • 115
  • 186
3
votes
1 answer

I would like to parse a boost::beast::flat_buffer with msgpack data using nlohmann:json

So I am using boost::beast as a WebSocket server. I would like to receive a binary message and parse it using nlohmann::json. However I get an error message: none of the 3 overloads can convert parameter "nlohmann::detail::input_adapter" Here is…
Ray Hulha
  • 10,701
  • 5
  • 53
  • 53
1
2
3
16 17