Questions tagged [nlohmann-json]
Use this tag for questions related to nlohmann JSON C++ library
0
votes
1answer
29 views
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 ...
-1
votes
1answer
39 views
Use nlohmann json to unpack list of integers to a std::vector<int>
I'm using https://github.com/nlohmann/json
It's awesome.
But .. is there any way to unpack:
{
"my_list" : [1,2,3]
}
into a std:vector<int> ?
I can't find any mention, and std::vector<...
0
votes
1answer
46 views
How to change json object name without changing its values in C++?
I'm using json for modern c++.
And I have a json file wich contains some data like:
{
"London": {
"Adress": "londonas iela 123",
"Name": "London",
"Shortname": "LL"
},
"Riga": {
"...
2
votes
1answer
56 views
Why is json file deleting old inputs from c++?
So 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.
...
1
vote
1answer
33 views
nlohmann json has a string member called name, how can I check it is null or valid string
I know that I have this:
json var["thirdName"].get<std::string>().c_str();
It is used in C++. The protocol says this member is mandatory, but lots of people don't have third name.
I got ...
0
votes
0answers
18 views
Link error when accessing static member of struct inside a template function inside of nlohman::json value only when optimisation is disabled [duplicate]
The title is a bit of a mouthful, but it's the best way I can think of describing the problem.
Anyway, on to the code:
#include <nlohmann-json/json.hpp>
using json = nlohmann::json;
template ...
0
votes
3answers
113 views
c++, JSON, get object members in an array
I am using nlohmann::json for parsing json in the program.
given a json there is an array with several objects, according to one of the object members I want to get other members of the same object.
...
0
votes
0answers
106 views
c++, JSON array parsing using nlohmann::json
In a json file imported into my c++ program there is such structure as:
{
"a":"1",
"ec":[
{
"a":"0x00",
"s":[
{"a":"0xA0"},
{"a":"0xA1"},
...
0
votes
1answer
93 views
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
votes
2answers
105 views
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 };
...
...
-1
votes
1answer
85 views
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.
...
0
votes
1answer
106 views
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<type>();
However, type x; x = json; doesn't work, because that would ...
0
votes
1answer
64 views
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",
"...
0
votes
1answer
192 views
nlohmann JSON C++ Include issue
I'm currently having an issue to where visual studio code is not recognizing the include of the json.hpp file no matter what I do in the IDE, I don't admittedly know if the issue is being caused by ...
0
votes
1answer
264 views
C++ nlohmann JSON get name of array
I have nlohmann json object:
json uuid = R"(
{
"uuid": ["aaa","bbb","ccc"]
}
)"_json;
I can get the values in array without ...
0
votes
1answer
44 views
how can I serialize 2 sets using nlohmann/json.hpp
I have two unordered sets of pairs (X,Y) implemented using boost hash and I would like to convert them to a Json file that has a special format.
unordered_set<pair<int,int>> visited, ...
1
vote
0answers
167 views
nlohmann json ambiguous overload for 'operator='
I'm getting this compilation error with the following code
#include <iostream>
#include <boost/optional.hpp>
#include "nlohmann_json.hpp"
namespace nlohmann {
template <typename T>
...
0
votes
0answers
38 views
Why is the 2nd time I try to change my JSON to string not working(the output window won't show up, even I have breakpts or getchar)?.
I am trying to convert my JSON object to a string in test case 1 and 4. When test case 4 is removed, the code works properly, like the output shows up. But when I include test case 4, the code won't ...
0
votes
2answers
261 views
How to read JSON content as it is in C++?
I am trying read a text file which has Valid JSON content but not string. The below code works fine if it is a string dump. For example - if file contents are like this "{ \"happy\": true, \"pi\": 3....
1
vote
0answers
132 views
Unicode character in json
i am working on to read data from json but json parser unable to decode some unicode characters. Below is the json data in the file i want to parse.
[{
"code": "BR",
"name": "Brazil",
"capital": "...
1
vote
1answer
1k views
How do you get a JSON object from a string in nlohmann json?
I have a string that I would like to parse into a json, but _json doesn't seem to work every time.
#include <nlohmann/json.hpp>
#include <iostream>
using nlohmann::json;
int main()
{
...
0
votes
1answer
446 views
c++ nlohmann json - how to test nested object is existent or empty
I have a nested Json like this:
string strJson = "{
"Header":
{"Version":"V0.00.01","ID":"1000","Name":"SetEnvValues"}
,
"Data":
{"Temp":0.00,"rH":0.00,"CO2":0.00,"O2":0.00 }
}";...
0
votes
1answer
2k views
JSON parsing using nlohmann json
I am trying to parse the JSON structure using nlohmann's json.hpp
. But I am not to create the JSON structure from the string. I have tried all the way, but still it is failing.
My requirement is ...
0
votes
1answer
1k views
Prettify a JSON string in C++ from a .txt file
I'm currently working in C++, getting an HTTP response from a request that I write into a .txt file using ostream. This happens asynchronously and I don't want to change this.
Once the data is done ...
0
votes
1answer
415 views
nlohmann JSON, change the value of a key
I'm using nlohmann::json and all I need to do is copy a JSON object and then alter some of the keys in it. Is it possible to alter keys in nlohmann::json objects?
Essentially what I'm trying to do is ...
0
votes
1answer
470 views
c++ return type of function returning json array via nlohmann json.hpp
I am parsing a json file using nlohmann's json.hpp. The part of the json file I am concerned with looks like this:
"image_captureOptions": {
"captureInterval" : 1000,
"captureLimit" : 5,
"...
0
votes
2answers
235 views
C++ nonlohmann json read child object
i'm actually working on a little program and i need to read a json file.
i'm using C++ and the nlohmann json libraries.
My current code
int main(int argc, const char** argv){
ifstream ifs("...
-1
votes
1answer
314 views
C++ no matching function for call when using push_back in older json::nlohmann library
#include "json.hpp"
#include <memory>
#include <vector>
#include <iostream>
struct json_node;
using json_node_ptr = std::shared_ptr<json_node>;
struct json_node
{
int id;...
4
votes
1answer
3k views
c++ nlohmann json - how to iterate / find a nested object
I am trying to iterate over a nested json, using nlohmann::json. My json object is below:
{
"one": 1,
"two": 2
"three": {
"three.one": 3.1
},
}
I am trying to iterate and /...
1
vote
1answer
1k views
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": ...
0
votes
2answers
385 views
How to properly parse JSON objects in a Java+C++ TCP connection?
So I want to have a TCP connection between a Java client and a C++ server. Think of the client as an input device and the C++ server should receive JSON objects, parse them and use them in a game.
It ...
0
votes
0answers
594 views
Passing JSON object by value or reference
I am usling nlohmann's JSON library to parse a JSON file. In this context I wondered it if is best practice to pass a JSON object by value or reference in terms of efficiency and overhead associated ...
3
votes
1answer
2k views
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 ...
-1
votes
1answer
55 views
Create JSON structure based on input variables
I have the following JSON file:
{
"outer_size":2,
"inner_size":{
"length_one":2,
"length_two":1
}
}
I will use this info to create a new JSON file, whose dimensions are ...
8
votes
1answer
3k views
Adding header-only dependencies with CMake
I have a simple project which requires three header-only libraries in order to compile: websocketpp, spdlog and nlohmann/json.
The project structure looks like this:
└── src
├── app
│ ├── ...
1
vote
0answers
151 views
How does nlohmann::json implement the nice deserialization syntax?
How nlohmann::json implement the nice deserialization syntax?
// You can create an object (deserialization) by appending _json to a string literal.
//create object from string literal
json j = "{ \"...
0
votes
1answer
354 views
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....
2
votes
1answer
2k views
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 ...
3
votes
4answers
3k views
How to convert a json object to a map with nlohmann::json?
For example, with nlohmann::json, I can do
map<string, vector<int>> m = { {"a", {1, 2}}, {"b", {2, 3}} };
json j = m;
But I cannot do
m = j;
Any way to convert a json object to a map ...
1
vote
1answer
651 views
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 ...
10
votes
2answers
9k views
C++: Reading a json object from file with nlohmann json
I am using the nlohmann's json library to work with json objects in c++. Ultimately, I'd like to read a json object from a file, e.g. a simple object like this.
{
"happy": true,
"pi": 3.141
}
I'm ...