title: C#: Insert a json object
body: <p>I have the following classes: </p>
  
  <pre><code>internal class RequestPayload1
  {
      [DataMember]
      [JsonProperty(Required = Required.Always)]
      internal string Date { get; set; }
  
      [DataMember]
      [JsonProperty(Required = Required.Always)]
      internal string State { get; set; }
  
      [DataMember]
      [JsonProperty]
      internal string Properties { get; set; }
  }
  
  internal class RequestPayload2
  {
      [DataMember]
      [JsonProperty(Required = Required.Always)]
      internal string Id { get; set; }
  
      [DataMember]
      [JsonProperty(Required = Required.Always)]
      internal string Name { get; set; }
  
      [DataMember]
      [JsonProperty]
      internal string Location { get; set; }
  }
  </code></pre>
  
  <p>I created an object of the two classes EntityEvent1 and EntityEvent2 class like this: </p>
  
  <pre><code>RequestPayload1 payload1 = new RequestPayload1()
  {
      Date = "date1",
      State = "state1",
      Properties = "properties1"
  };
  
  RequestPayload2 payload2 = new RequestPayload2()
  {
      Id = "id1",
      Name = "name1",
      Location = "location1"
  };
  </code></pre>
  
  <p>I have a class:</p>
  
  <pre><code>internal class RequestData
  {
      [DataMember]
      [JsonProperty(Required = Required.Always)]
      internal string RequestHeader { get; set; }
  
      [DataMember]
      [JsonProperty(Required = Required.Always)]
      internal JObject RequestPayload { get; set; }
  }
  </code></pre>
  
  <p>I need the RequestPayload to be set to either RequestPayload1 or RequestPayload2. That is the reason I used the type JObject for it. But when I serialize the payloads like this, the RequestPayload is getting the object in an invalid Json format. Mainly the double quotes replaced with single quotes: </p>
  
  <pre><code>string requestPayload1 = JsonConvert.SerializeObject(payload1);
  RequestData requestData1 = new RequestData()
  {
     RequestHeader = "requestHeader1",
     RequestPayload = new JObject(payload1);
  };
  
  string requestPayload2 = JsonConvert.SerializeObject(payload2);
  RequestData requestData2 = new RequestData()
  {
     RequestHeader = "requestHeader2",
     RequestPayload = new JObject(payload2);
  }
  </code></pre>
  
  <p>requestData1 and requestData2 when deserialized are giving: </p>
  
  <pre><code>"Request": {
      "RequestHeader": "requestHeader1",
      "RequestPayload": {'Date':'date1','State':'state1', 'Properties':'properties1'}""
    }
  
  "Request": {
      "RequestHeader": "requestHeader2",
      "RequestPayload": "{'Id':'id1','Name':'name1', 'Location':'location1'}"
    }
  </code></pre>
  
  <p>How can I change this so that requestData1 and requestData2 are: </p>
  
  <pre><code>"Request": {
      "RequestHeader": "requestHeader2",
      "RequestPayload": {
          "Date":"Date",
          "State":"state1",
          "Properties":"properties1"
      }
    }
  
  "Request": {
      "RequestHeader": "requestHeader2",
      "RequestPayload": {
          "Id":"id1",
          "Name":"name1",
          "Location":"location1"
      }
    }
  </code></pre>
  
  <p>I probably have to change the type of RequestPayload to something other than JObject, but not sure which one. </p>