title: System.Text.Json Serialize dictionary as array
body: <p>Is it possible to serialize (and deserialize) a dictionary as an array with System.Text.Json?</p>
  
  <p>Instead of <code>{ "hello": "world" }</code> I would need my dictionary serialized as <code>{ "key": "hello", "value": "world" }</code> preferably without having to set attributes on the dictionary property of my class.</p>
  
  <p>Using newtonsoft.json it was possible this way:</p>
  
  <pre><code>class DictionaryAsArrayResolver : DefaultContractResolver
  {
      protected override JsonContract CreateContract(Type objectType)
      {
          if (objectType.GetInterfaces().Any(i =&gt; i == typeof(IDictionary) || 
             (i.IsGenericType &amp;&amp; i.GetGenericTypeDefinition() == typeof(IDictionary&lt;,&gt;))))
          {
              return base.CreateArrayContract(objectType);
          }
  
          return base.CreateContract(objectType);
      }
  }
  </code></pre>