I\'m receiving a JSON object from a public API with a property that, itself, is an escaped JSON string.
{
\"responses\":[
{
\"info\":\"keep
string Body {get; set;}Here's a program that does it with the dynamic type and anonymous objects.
static void Main(string[] args)
{
var json = File.ReadAllText("JsonFile1.json");
dynamic obj = JsonConvert.DeserializeObject(json);
var dest = new
{
responses = ((IEnumerable)obj.responses).Select(x => new
{
info = x.info,
body = JsonConvert.DeserializeObject((string)x.body)
})
};
var destJson = JsonConvert.SerializeObject(dest);
File.WriteAllText("JsonFile2.json", destJson);
}
Alternatively, you can just construct a new version of whatever your destination type is instead of an anonymous type, if you don't feel like reserializing the josn.