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

Having trouble opening a json file in C++

I am trying to open a json file that I will be working with in C++. Code that I have used successfully before fails to open the file. I am using Visual Studio 2017 on Windows 10 Pro with JSON for Modern C++ version 3.5.0. I have a very simple…
Al G
  • 115
  • 4
  • 10
0
votes
1 answer

nlohmann parsing a json file without knowing keys

I'm using nlohmann/json library to use json in cpp. I have a Json::Value object and I would like to go through my json data by exploring the keys without knowing them. I came across the documentation but only found the object["mySuperKey"] method to…
pipou
  • 270
  • 3
  • 15
0
votes
0 answers

How to see which line while parsing json source caused the exception?

I have JSON files with hundreds of lines, but when there is an error that causes a parsing exception, the library returns a character position, not a line number. Line number would be hugely helpful since most text editors will show you, or take you…
Dan
  • 101
  • 1
0
votes
2 answers

JSON parser for C++

I'm trying to parse Json file and store the data into 2D array or vector. The Json file looks like this: {"n" : 2, "x" : [[1,2], [0,4]]} And this is what my code looks like and but I keep getting "json.exception.parse_error.101"…
5a9ar
  • 1
  • 2
0
votes
0 answers

How to search array of json objects and return matching object using nlohmann-json

Imagine there is an array of account objects [ {"account_number":1,"customer_name":"John"}, {"account_number":2,"customer_name":"Sally"} ] I want to write a method that takes in an account number and returns the matching account object. I…
pd227
  • 1
0
votes
1 answer

How to add object member in array?

I have json file like this. Use nlohmann. {"Fans": [ { "MemberID": "0", "Name": "Fan 0 ABC", "Reading": 30 }, { "MemberID": "1", "Name": "Fan 1 ABC", …
Toby
  • 3
  • 3
0
votes
1 answer

How do I solve exception generated due to string to json conversion?

I am trying to understand JSON to string and string to JSON conversion using nlohmann framework for JSON library in C++. However I am getting problem with exception generated and I am not understanding the reason why it is being generated. The…
0
votes
2 answers

Creating a json database with user input

I need to create my .json array to look like this: { "airports": [{ "address": "Horley, Gatwick RH6 0NP, UK", "city": "London", "shortVersion": "LGW" }, { "address": "Marupe, LV-1053", …
Supreez
  • 3
  • 1
0
votes
1 answer

C++ Json Key variable issue

I'm having an issue with my code for jSon object conversion. I am trying to write a loop that takes in a vector and if the vector has an inversion then store that in a jSon Object. The only real problem I am having is the correct output. I am…
0
votes
1 answer

Cross-compilation errors Visual studio C++

I recently converted my Windows C++ application to a Linux c++ application and use a Windows subsystem with Debian to cross-compile to Linux. However, I get the following error by using the json library by nlohmann no match for 'operator-' (operand…
Thomas Wagenaar
  • 6,489
  • 5
  • 30
  • 73
0
votes
1 answer

Why nlohmann/json serialize "null" instead of "0" on double?

Let say I partially init a native double array in C++ and serialize it with nlohmann/json: const int numPoints = 10; double mLengths[numPoints]; for (int i = 0; i < 5; i++) { mLengths[i] = i + 0.1 * i; } nlohmann::json…
markzzz
  • 47,390
  • 120
  • 299
  • 507
0
votes
2 answers

How to deserialize an array?

I'm using the nlohmann::json library to serialize/deserialize elements in json. Here's how I serialize a C++ array of double: double mLengths[gMaxNumPoints] = { 1.0, 2.0, 3.0, 4.0, 5.0 }; ... nlohmann::json jsonEnvelope; jsonEnvelope["lengths"] =…
markzzz
  • 47,390
  • 120
  • 299
  • 507
0
votes
1 answer

How to assign derived class from base ptr to nlohmann::json

I am playing with some kind of shared object framework. It is using nlohmann::json to provide message passing and configuration and loads message handlers and datasources depending of the json config. As I am using value classes, which all derive…
Plurax
  • 44
  • 6
0
votes
1 answer

Nlohmann json get with type deduction

With nlohmann::json an object can be parsed using a couple different expressions: type x = json; type x; x = json.get(); However, type x; x = json; doesn't work, because that would require adding a new assignment operator for type. I find…
SU3
  • 5,064
  • 3
  • 35
  • 66
0
votes
1 answer

nlohmann creating multilevel objects dynamically

I need to create the following structure but I am struggling to do this using json. { "ParentTree": [{ "Name": "Name3", "children": [{ "Name": "Name2", "children": [{ "Name": "Name1", …
Arun
  • 2,247
  • 3
  • 28
  • 51