title: Serializing a custom subclass of NameValueCollection with Json.Net
body: <p>I have the following class I am unsuccessfully attempting to serialize to Json.</p>
  
  <pre class="lang-cs prettyprint-override"><code>class HL7 : NameValueCollection
  {
    public List&lt;HL7&gt; Children { get; set; }
    public HL7()
    {
      Children = new List&lt;HL7&gt;();
    }
  }
  </code></pre>
  
  <p>I have created the object like so and added data to it:</p>
  
  <pre class="lang-cs prettyprint-override"><code>HL7 hl7 = new HL7();
  hl7.Add("a", "123");
  hl7.Add("b", "456");
  hl7.Children.Add(new HL7());
  hl7.Children[0].Add("c", "123");
  hl7.Children[0].Add("d", "456");
  </code></pre>
  
  <p>When I call</p>
  
  <pre class="lang-cs prettyprint-override"><code>JsonConvert.SerializeObject(hl7)
  </code></pre>
  
  <p>I receive</p>
  
  <pre class="lang-JSON prettyprint-override"><code>["a","b"]
  </code></pre>
  
  <p>I was expecting the following:</p>
  
  <pre class="lang-JSON prettyprint-override"><code>{
    "a": "123",
    "b": "456",
    "Children": [
      {
        "c": "123",
        "d": "456",
      }
    ]
  } 
  </code></pre>