title: How to properly dynamically create custom JSON through Serializer
body: <p>I have a roadblock where I have to transform a simple User class to a very specific JSON in the form of</p>
  <pre><code>{&quot;fields&quot;: {
              &quot;Name&quot;: {
                  &quot;stringValue&quot;: &quot;test&quot;
              },
              &quot;Password&quot;: {
                  &quot;stringValue&quot;: &quot;Password&quot;
              },
              &quot;email&quot; : {
                  &quot;stringValue&quot; : &quot;emailexample&quot;
              }
          }}
  </code></pre>
  <p>where stringValue is the value of the class variable which is enclosed in the name of the variable. So far I've tried to create my own Serializer to fix this but I can only create one field ie</p>
  <pre><code>{&quot;Fields&quot;: {&quot;email&quot;: {&quot;stringValue&quot;: &quot;emailexample&quot;}}}
  </code></pre>
  <p>before I get the error of Newtonsoft.Json.JsonException: 'Newtonsoft.Json.Linq.JProperty cannot have multiple values.', So I'm wondering if my way of doing it is even possible (this is my first time trying to create a custom serializer) or if I need to approach this in a completely different direction. What I've tried so far is below.</p>
  <pre><code>public override void WriteJson(JsonWriter writer, User value, JsonSerializer serializer)
  {
      JToken t = JToken.FromObject(value);
  
      if (t.Type != JTokenType.Object)
      {
          t.WriteTo(writer);
      }
      else
      {
          JObject o = (JObject) t;
          IList&lt;string&gt; values = o.Properties().Select(p =&gt; p.Value.ToString()).ToList();
          IList&lt;string&gt; names = o.Properties().Select(p =&gt; p.Name).ToList();
  
          //o.RemoveAll();
          
          JObject val = new JObject(new JProperty(&quot;stringValue&quot;, new JValue(values[0])));
          JProperty fields = new JProperty(names[0], val);
          JObject field = new JObject(fields);
          JProperty test = new JProperty(&quot;Fields&quot;, field);
          for (int i=1; i&lt;names.Count;i++)
          {
              val = new JObject(new JProperty(&quot;stringValue&quot;, new JValue(values[i])));
              JProperty name = new JProperty(names[i], val);
              JObject jObject = new JObject(name);
              test.Add(jObject);
          }
          
          o.WriteTo(writer);
      }
  }
  </code></pre>