.net - JSON.NET: How to insert an existing JSON into the middle of another? -
is there easy way insert existing json file middle of ?
i have seen others asking how merge them think problem unique, can't seem find info on it
i appreciate on matter
thanks
edit
here first json.
{ name: "test1", items: { name: "test1items" } }
i need insert second json, valid json new property called "data" on first json, data property don't see doesn't exist,its below items. so
{ name: "test1", items: { name: "test1items", data: ........ } }
so idea use sort of reader on first json , find items.name , add new property "data" , merge in second json.
i haven't included second json shouldn't matter, valid json string.
i have in strings can parse them etc ?
i hope helps explanation
string json1 = @" { name: ""test1"", items: { name: ""test1items"" } }"; string json2 = @" { ""somefield"": ""somedata"" }"; var obj1 = jobject.parse(json1); var obj2 = jobject.parse(json2); obj1["items"]["data"] = obj2; var newjson = obj1.tostring();
and output:
{ "name": "test1", "items": { "name": "test1items", "data": { "somefield": "somedata" } } }
Comments
Post a Comment