Hi @Abdeali Mandviwala,
You can use JSON.NET
to achieve your requirement. Be sure install Microsoft.AspNetCore.Mvc.NewtonsoftJson
package If your project version is beyond .NET Core 3.x.
A simple working demo you could follow:
string jsonString = @"{
""data"": [
{
""order"": 1,
""table_no"": 94683,
""table_book_date"": ""20240103100000""
},
{
""order"": 2,
""table_no"": 94544,
""table_book_date"": ""20240103100000""
}
]
}";
var jsonObject = JsonConvert.DeserializeObject<JObject>(jsonString);
var dataArray = jsonObject["data"] as JArray;
var resultData = new List<object>();
var element = "table_no";
foreach (var item in dataArray)
{
var tableNo = item[element];
resultData.Add(new { table_no = tableNo });
}
var resultObject = new { data = resultData };
string resultJson = JsonConvert.SerializeObject(resultObject, Formatting.Indented);
// Print the result
Console.WriteLine(resultJson);
Result:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Rena