I am using Newtonsoft.JSON to serialize a DataTable into a single JSON payload.
The resulting payload looks like:
[
{
"Name" : "Example_Name_1",
"Value": "Example Value 1"
},
{
"Name" : "Example_Name_2",
"Value": "Example Value 2"
},...
]
For use with an external library, I need it to like:
[
{
"Name" : "Example_Name_1",
"Value": {
"Value": "Example Value 1"
}
},
{
"Name" : "Example_Name_2",
"Value": {
"Value": "Example Value 2"
}
},...
]
Is the any way to make this transformation? I've been looking at Regular Expressions, but haven't had any luck.
I've been playing with different regex patterns and I saw another SO solution that was similar, but used JavaScript Mappings?
var strJson = "[{\"Name\": \"Example_Name_1\",\"Value\": \"Example Value 1\"}]";
var pattern = "{\"Name\": \"*\",\"Value\": \"*\"}";
var replacement = "{\"Name\": \"*\",\"Value\": {\"Value\": \"*\"}}";
var input = strJSON;
var result = Regex.Replace(input, pattern, replacement);
return result;
[EDIT] The DataTable has just 2 columns: Property_Name, & Property_Value I'm serializing it with
JsonConvert.SerializeObject(myDataTable);