Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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??

like image 281
user1025852 Avatar asked Oct 16 '12 11:10

user1025852


People also ask

How do I combine two json responses?

We can merge two JSON objects using the putAll() method (inherited from interface java.

How do I combine two json objects with the same key?

Use concat() for arrays Assuming that you would like to merge two JSON arrays like below: var json1 = [{id:1, name: 'xxx' ...}] var json2 = [{id:2, name: 'xyz' ...}]

Can we merge two json files?

This is a simple tool for merging multiple data. json files into one.

How do I link two json files?

If you just want to merge all json files sequentially, go to the folder where all json files are, select all and rename the first one as "yourchoice", by doing this all will be in sequential order i.e. yourchoice1,yourchoice2 ... next go to cmd and type : copy *. json "outputfilename".


1 Answers

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) });
like image 193
L.B Avatar answered Oct 17 '22 16:10

L.B