user1025852
user1025852

Reputation: 2784

JSON.NET \ how to concat two JSONs in JSon.net

I have two JSONs (as simple strings) - is there neat way to concat them? As part of the infrastructure??

Upvotes: 5

Views: 10477

Answers (1)

L.B
L.B

Reputation: 116108

string j1 = @"{""a"":1}";
string j2 = @"{""b"":2}";

var j = JsonConvert.SerializeObject(new[] { JsonConvert.DeserializeObject(j1), 
                                            JsonConvert.DeserializeObject(j2) });

or

var j = JsonConvert.SerializeObject(new { obj1 = JObject.Parse(j1), 
                                          obj2 = JObject.Parse(j2) });

Upvotes: 10

Related Questions