Input JSON:
{
"name" : "objname",
"abc" : 1,
"def" : 2
}
Desired output JSON:
{
"objname" :
{
"abc" : 1,
"def" : 2
}
}
I tried as shown below, but I feel it's not the correct way.
// This is the class object
public class Obj
{
public string Name { get;set;}
public string abc { get; set; }
public string def { get; set; }
}
var obj = JsonConvert.DeserializeObject<Obj>(json);
StringBuilder sb = new StringBuilder();
sb.Append(" { ");
sb.AppendLine(obj.Name);
sb.AppendLine(" : {");
sb.AppendLine(GetMemberName(() => obj.abc) + ":" + obj.abc + ",");
sb.AppendLine(GetMemberName(() => obj.def) + ":" + obj.abc);
sb.AppendLine(" : }");
"objname" : { "abc" : 1, "def" : 2 }isn't even JSON, it's missing the outer{and}. 2) What have you tried so far?{or[. It's perfectly valid to have a JSON document which is just a string, null token or number for example. But yes, for an object, you do need the braces.