Serialize Dictionary<TKey, TValue> to JSON with DataContractJsonSerializer
I have an object tree that I'm serializing to JSON with DataContractJsonSerializer . Dictionary<TKey, TValue> gets serialized but I don't like the markup - the items are not rendered like this: {key1:value, key2:value2} but rather like an array of serialized KeyValuePair<TKey, TValue> objects: [{ "__type":"KeyValuePairOfstringanyType:#System.Collections.Generic", "key":"key1", "value":"value1" }, { "__type":"KeyValuePairOfstringanyType:#System.Collections.Generic", "key":"key2", "value":"value2" }] Ugly, isn't it? So, I avoid this by wrapping the generic Dictionary in a custom object that