title: How to create json string from C# list of object with specific properties?
body: <p>Consider I have below values in the drop-down (<code>dropDownList</code> variable) and user selected values are in <code>selectedDropDownValues</code> list.</p>
  
  <p>And DB api returns the list of customers (<code>customerDBList</code> variable). </p>
  
  <p>Now the requirement is to build JSON from selected values as mentioned below -</p>
  
  <pre><code>var dropDownList = new[] { "Customer.Id", "Customer.FirstName", "Customer.LastName", "Customer.Address.AddressLine1", "Customer.Address.AddressLine2" };
  
  var selectedDropDownValues = new[] { "Customer.Id", "Customer.FirstName", "Customer.Address.AddressLine1" };
  
  var customerDBList = new List&lt;Customer&gt;(){
                  new Customer {
                      Id=1,
                      FirstName="John",
                      LastName="Desouza",
                      Address=new Address{            
                                  AddressLine1="1 Street",
                                  AddressLine2="Linking Road"
                      }},        
                  new Customer {
                      Id=2,
                      FirstName="Sam",
                      LastName="Lewis",
                      Address=new Address{            
                                  AddressLine1="Fedral Highway",
                                  AddressLine2="Louisville"
                      }                
                  }};
  </code></pre>
  
  <p>Expected JSON output as -</p>
  
  <pre><code>[
    {
      "Customer": {
        "Id": 1,
        "FirstName": "John",
        "Address": {
          "AddressLine1": "1 Street"
        }
      }
    },
    {
      "Customer": {
        "Id": 2,
        "FirstName": "Sam",
        "Address": {
          "AddressLine1": "Fedral Highway"
        }
      }
    }
  ]
  </code></pre>