How to add sorted json('sortedJson') back to the whole json('jObj') below? Or is there an alternative to do the below?
Json:
{
"Information": [
{
"FieldName": "Area04",
"Draft": "Unknown",
},
{
"FieldName": "Area02",
"Draft": "Unknown",
},
{
"FieldName": "Area01",
"Draft": "Unknown",
},
{
"FieldName": "Area03",
"Draft": "Unknown",
}
],
"OtherInfo": []
}
Code:
static void Main(string[] args)
{
string _json = "{'Information': [{'FieldName': 'Area04','Draft': 'Unknown'},{'FieldName': 'Area02','Draft': 'Unknown'},{'FieldName': 'Area01','Draft': 'Unknown'},{'FieldName': 'Area03','Draft': 'Unknown'}],'OtherInfo': []}";
var jObj = JsonConvert.DeserializeObject<Informat>(_json);
var test1 = jObj.Information.OrderBy(x => x.FieldName);
var sortedJson = JsonConvert.SerializeObject(test1);
//Add code to merge 'sortedJson' to '_json'
}
Class:
public class Informat
{
public Information[] Information { get; set; }
public object[] OtherInfo { get; set; }
}
public class Information
{
public string FieldName { get; set; }
public string Draft { get; set; }
}
I dont know how to add the sorted json back to whole json. Could you please help me with this?