title: Get a dynamic object for JsonConvert.DeserializeObject making properties uppercase
body: <p>I am not sure how to seek help and this is kind of unusual I agree, so please pardon me. I'll try to explain as below:</p>
  
  <p>• I am consuming JSON using POST and getting a dynamic object. I need to convert all incoming properties in dynamic object to uppercase. </p>
  
  <p>• I am using what <strong><em>I think</em></strong> is a bodged solution. I'm converting JSON to string Dictionary, then putting values into a new dictionary after converting the Key to Key.ToUpper() and then deserializing it back into a dynamic object.</p>
  
  <p>Current <strong>working</strong> solution is as follows:</p>
  
  <pre><code>string _StrJSON = @"{""FIELDA"" : ""1234"",""fieldb"" : ""OtherValue""}";
  
  var d = JsonConvert.DeserializeObject&lt;Dictionary&lt;string, string&gt;&gt;(_StrJSON);
  
  d.ContainsKey("FIELDB").Dump(); // returns false, obviously.
  
  Dictionary&lt;string, string&gt; dr = new Dictionary&lt;string, string&gt;();
  
  d.ToList().ForEach(r =&gt; dr.Add(r.Key.ToUpper(), r.Value));
  
  dr.Dump("dr"); // FIELDA 1234  - FIELDB OtherValue 
  
  var a  = JsonConvert.SerializeObject(dr);
  a.Dump(); // {"FIELDA":"1234","FIELDB":"OtherValue"}
  </code></pre>
  
  <p>This works.</p>
  
  <p>[EDIT]
  Some confusion about my "var" above and other stuff. I am very clear on what is dynamic and what isn't. 
  [/EDIT]</p>
  
  <p>What I have tried so far which <strong>DOES NOT WORK</strong> is as below:</p>
  
  <pre><code>namespace Newtonsoft.Json
  {
  /// &lt;summary&gt;
  /// Converts JSON keys to uppercase.
  /// &lt;/summary&gt;
  public class UppercaseContractResolver : Serialization.DefaultContractResolver
  {
      #region Methods.
  
      #region Public Methods.
  
      /// &lt;summary&gt;
      /// Resolves property name for this JSON object.
      /// &lt;/summary&gt;
      /// &lt;param name="key"&gt;&lt;/param&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      protected override string ResolvePropertyName(string key)
      {
          return key.ToUpper();
      }
  
      #endregion
  
      #endregion
  
      #region Constructors.
  
      /// &lt;summary&gt;
      /// Converts JSON keys to uppercase.
      /// &lt;/summary&gt;
      public UppercaseContractResolver()
      {
      }
  
      #endregion
  }
  
  /// &lt;summary&gt;
  /// Wrapper for Newtonsoft.Json.JsonConvert for JSON keys as uppercase.
  /// &lt;/summary&gt;
  public static class JsonConvertUpper
  {
      #region Members.        
      #endregion
  
      #region Methods.
  
      #region Public Methods.
  
      /// &lt;summary&gt;
      /// Tries to serialize specified object with JSON keys in upper case.
      /// &lt;para&gt;e.g. "key":value should become "KEY":value by using this method.&lt;/para&gt;
      /// &lt;/summary&gt;
      /// &lt;param name="value"&gt;Object.&lt;/param&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public static string SerializeObjectUpper(object value)
      {
          return JsonConvert.SerializeObject(value, new JsonSerializerSettings
          {
              ContractResolver = new UppercaseContractResolver()
          });
      }
  
      /// &lt;summary&gt;
      /// Tries to Deserialize specified object with JSON keys in upper case.
      /// &lt;para&gt;e.g. "key":value should become "KEY":value by using this method.&lt;/para&gt;
      /// &lt;/summary&gt;
      /// &lt;param name="strValue"&gt;String.&lt;/param&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public static object DeserializeObjectUpper(string strValue)
      {
          // DeserializeObject does not allow uppercase properties. So use SerializeObjectUpper and then deserialize.
  
          var value = JsonConvert.DeserializeObject(strValue);
  
          string strJSON = SerializeObjectUpper(value);
  
          return JsonConvert.DeserializeObject(strJSON, new JsonSerializerSettings()
          {
              ContractResolver = new UppercaseContractResolver()
          });
      }
  
      #endregion
  
      #endregion
  }
  }
  </code></pre>
  
  <p>The method call for above would be:</p>
  
  <pre><code>  dynamic json = JsonConvertUpper.DeserializeObjectUpper(_StrJSON);
  
                  if (json.CTN== null)
                  {...}
  </code></pre>
  
  <p>[EDIT]
  Please note I don't have classes as JSON keys have to be treated as UPPERCASE and classes and other code etc are all in ProperCase.
  [/EDIT]</p>
  
  <p>Any way of doing it <strong><em>inside</em></strong> JsonConvert at all? To avoid my manual patch? Any help is appreciated. Thanks.</p>