title: How to dynamically generate json in c#
body: <p>The following class is just an entity for registration.</p>
  
  <pre><code>&gt;   class registration
  &gt;     {
  &gt;     public string email
  &gt;             {
  &gt;                 get;
  &gt;                 set;
  &gt;             }
  &gt;             public string birthday
  &gt;             {
  &gt;                 get;
  &gt;                 set;
  &gt;             }
  &gt;             public string first_name
  &gt;             {
  &gt;                 get;
  &gt;                 set;
  &gt;             }
  &gt;     }
  </code></pre>
  
  <p>There is a signup method where i am processing the values which i got from the user.I have not included full code here.just give a brief information.I will process the fields and convert one json format.I will send the json input to webapi service for further process.</p>
  
  <blockquote>
    <p>class RegisterProcess { public void SignUp(registration regObj) {</p>
  
  <pre><code>        JProperty UserProfile = new JProperty("RegisterProfile",
                                 new JObject(
                                 new JProperty("email", regObj.email),
                                 new JProperty("birthday", regObj.birthday),
                                 new JProperty("first_name", regObj.first_name))); } }
  </code></pre>
  </blockquote>
  
  <p>Some users might enter values for all fields &amp; some of them will enter only for few fields.I want to insert only field which has a value.I want to dynamically generate JProperty UserProfile stuff.(for example:If an user enter only email&amp;first_name,I want to create json only for those field.Null value should not be included.How to dynamically generate Json format.any ideas?</p>
  
  <p>Scenario :: Registration entity - I will use for registration process as well as updateprofile process.During registration user might enter email,first_name,birthday.later he want to update only email field.He will enter data for that field alone.At that time i want to generate json rpoperty only for email field.it should not disturb[first_name and birthday] field.if i send [registration MyReg = new registration { email = "me@mail.com"};],It will set [first_name and birthday field] as null.It shouldn't set null for those fields.it should retain the value which i entered while registration.i hope you got it</p>