-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
concatenate objects #252
Comments
The exception "cannot use push_back() with object" is due to the fact that (You originally reported a segmentation fault, and I was worried there was a bug ;-)) Unfortunately, the requested functionality is not present at this moment. Looking at Stack Overflow, it seems that |
Thanks for quick response and sorry about the initial text; no bugs indeed! I actually do not know how to achieve what I want, regardless of syntax and I wonder if it's possible to add new objects to |
Hi @mlund, you can achieve merging objects with the following function: json merge(const json &a, const json &b)
{
json result = a.flatten();
json tmp = b.flatten();
for (json::iterator it = tmp.begin(); it != tmp.end(); ++it)
{
result[it.key()] = it.value();
}
return result.unflatten();
} It is based on the I hope this helps! |
Thanks! Alternatively, this also worked for my purpose: for (auto it=b["sec"].begin(); it!=b["sec"].end(); it++)
a["sec"].push_back( json::object_t::value_type(it.key(), it.value()) ); |
Hi, is this usefull for include one json object into other? i've get some errors 😞 |
This basically implements the similar |
Thats greate! No, i need to concatenate one json object into a specific index of another, something like: Entities["table"] = mergeJSON(Entities, ReadedEntity); Where mergeJSON is the merge function what i getted from this topic. How can i do that? |
Could you provide an example for |
Entities: {"CSVMsg": {
"name": "PacketEntities",
"class":35,
"id":2,
"serial":782
}
} ReadedEntity: {"table":
{"name": "DC_Player",
"fields": {
"0": {"m_flSimulationTime": 47},
"1": {"m_nTickBase": 160748},
"2": {"m_vecOrigin": {
"0": 299.141327,
"1": 2343.210938
},
},
"3": {"m_vecOrigin2": -250.849808}
}
}
} Need something like: {"CSVMsg": {
"name": "PacketEntities",
"class":35,
"id":2,
"serial":782,
"table":
{"name": "DC_Player",
"fields": {
"0": {"m_flSimulationTime": 47},
"1": {"m_nTickBase": 160748},
"2": {"m_vecOrigin": {
"0": 299.141327,
"1": 2343.210938
},
},
"3": {"m_vecOrigin2": -250.849808}
}
}
}
} |
For your example, the following should do: Entities["CSVMsg"]["table"] = ReadedEntity["table"]; |
I don't test it already, but you are a kind of genius for my. Thank you a lot! |
Hey
|
We discuss a merge operation for objects in #661. |
@Dariusz1989 FYI, the |
Hi!
I wish to concatenate two json objects and thought of this:
which however throws an exception with v1.1.0. Any suggestions how to best do this?
Best, Mikael
The text was updated successfully, but these errors were encountered: