Using c# and .net 4.8 I need to combine 2 json strings. For this I'm using the JObject, but if you have a better (more efficient/faster) way to do this, please let know. this will run on the server so efficient is important.
This is what I'm doing now:
string json1 = "{\"Header1\":[[[\"id\",\"b2a30048-fdd3-490d-a8c2-0da023349aa1\"],[\"name\",\"A Cool Name\"],[\"rating\",3.3],[\"timeStamp\",\"2021-02-04T15:45:39.0844116-06:00\"]]]}";
string json2 = "{\"Header2\":[[[\"id\",\"b2a30048-fdd3-490d-a8c2-0da023349aa1\"],[\"name\",\"A Cool Name\"],[\"rating\",3.3],[\"timeStamp\",\"2021-02-04T15:45:39.0844116-06:00\"]]]}";
JObject test1 = JObject.Parse(json1);
JObject test2 = JObject.Parse(json2);
var result = new JObject();
result.Merge(test1);
result.Merge(test2);
Console.WriteLine(result);
As you can see, the json strings are compact text. However, result.ToString() looks like this:
{
"Header1": [
[
[
"id",
"b2a30048-fdd3-490d-a8c2-0da023349aa1"
],
[
"name",
"A Cool Name"
],
[
"rating",
3.3
],
[
"timeStamp",
"2021-02-04T15:45:39.0844116-06:00"
]
]
],
"Header2": [
[
[
"id",
"b2a30048-fdd3-490d-a8c2-0da023349aa1"
],
[
"name",
"A Cool Name"
],
[
"rating",
3.3
],
[
"timeStamp",
"2021-02-04T15:45:39.0844116-06:00"
]
]
]
}
and if this was a large json it would be very bloated for sending across the wire.
Please let me know the most efficient way to do this getting compact results.
Thank you.