I highly suggest you to use JSON library, for example Json.Net.
First of all, you'll be able to work with strongly typed objects, in addition you will avoid typos and similar bugs since the serializer will do the serialization for you.
public void Test()
{
string a = ""; //content of 'a' variable
string b = ""; //content of 'b' variable
var obj = new RootObject();
obj.Fields = new Fields();
obj.Fields.Summary = a;
obj.Fields.Description = b;
var jsonOutput = Newtonsoft.Json.JsonSerializer.Serialize(obj, typeof(RootObject));
}
public class Fields
{
[JsonProperty("summary")]
public string Summary { get; set; }
[JsonProperty("description")]
public string Description { get; set; }
}
public class RootObject
{
[JsonProperty("fields")]
public Fields Fields { get; set; }
}
Note: If you don't want to create unnecessary types, you can work directly with JObject, this is one of possible uses:
var jobj = Newtonsoft.Json.Linq.JObject.FromObject(new {
fields = new {
summary = a,
description = b
}
});
var jsonOutput = jobj.ToString();
aandbas values of those JSON properties?