0

I have the following string:

{"data.childData1":"s1","data.childData2":"s2",...}

How do I convert it to:

{"data":{
     "childData1":"s1",
      "childData2":"s2"
   }
}
2
  • 2
    What you need is formatted JSON, not valid json. Both of them are valid examples of JSON. plus, I am not sure about the extra set of {} in your second sample Commented Jan 8, 2015 at 14:45
  • How do I format it with JSON.net Commented Jan 8, 2015 at 14:46

1 Answer 1

0

You can use this lib to beautify json, or use Json.NET (example source):

public string GetPrettyPrintedJson(string json)
{
    dynamic parsedJson = JsonConvert.DeserializeObject(json);
    return JsonConvert.SerializeObject(parsedJson, Formatting.Indented);
}
Sign up to request clarification or add additional context in comments.

2 Comments

The result is still the same. No change.
Ohhhh I misunderstood your question. What you want to do is not standard, you will probably have to implement it yourself.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.