Here is a sample program.
For clarity, I just manually created the source data with a class initialization.
The OP will mostly likely need to create the source data class instance with JsonConvert.DeserializeObject<sourceroot>(sourceJsonData) statement;
Here is a
link to a tool that will create a C# class based on Json structures. It can be very helpful.
Code was built in Visual Studio 2019, and is a .Net 4.8 framework Console application.
using Newtonsoft.Json;
using System.Collections.Generic;
namespace CodeProject_JSonConverter
{
class Program
{
static void Main(string[] args)
{
var sourceData = new SourceRoot
{
error = false,
parameters = new List<SourceParameter>
{
new SourceParameter {Name = "Vasanthakumar", FirstName = "Vasanth", LastName = "Kumar", Phone = "1234567890"}
}
};
var targetData = new TargetRoot();
targetData.parameters = new List<TargetParameter>();
targetData.error = sourceData.error;
foreach (var item in sourceData.parameters)
{
targetData.parameters.Add(new TargetParameter { key = nameof(SourceParameter.Name), value = item.Name });
targetData.parameters.Add(new TargetParameter { key = nameof(SourceParameter.FirstName), value = item.FirstName });
targetData.parameters.Add(new TargetParameter { key = nameof(SourceParameter.LastName), value = item.LastName });
targetData.parameters.Add(new TargetParameter { key = nameof(SourceParameter.Phone), value = item.Phone });
}
var targetJson = JsonConvert.SerializeObject(targetData);
}
}
public class SourceRoot
{
public bool error { get; set; }
public List<SourceParameter> parameters { get; set; }
}
public class SourceParameter
{
public string Name { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Phone { get; set; }
}
public class TargetRoot
{
public bool error { get; set; }
public List<TargetParameter> parameters { get; set; }
}
public class TargetParameter
{
public string key { get; set; }
public string value { get; set; }
}
}