I am tring to create nested json string here is my json string below,
[
{
\'CompanyID\':\'1\',
\'Name\':\'Company1\',
\'DepartmentName\'
One of the cleanest ways of such manipulation is with using classes. Based on the json you initially provided, and your initial question, you can do the following.:
class Company
{
public int CompanyID { get; set; }
public string Name { get; set; }
public string DepartmentName { get; set; }
public object Modify => new {
CompanyID, Name, department = new { DepartmentName }
};
}
Then you can simply deserialize into a list, convert it with the help of Linq
and serialize it
var modifiedList = JsonConvert.DeserializeObject<List<Company>>(jsonCompany).Select(c => c.Modify);
string updatedJson = JsonConvert.SerializeObject(modifiedList);
Since your code seems to show a different json, you may have to modify the Linq part according to what you are actually trying to do. You can look into Linq to check what exactly you are trying to do.