title: How to store IList (Collection) of C# as Json document in DynamoDb
body: <p>I have a <code>ASP.Net Core 2.1</code> app which is using <code>DynamoDb</code> as Db (NoSql)</p>
  
  <p>DTO</p>
  
  <pre><code>public class CustomerTO
  {  
   public string Id{get; set;}
   public string Name {get; set;}
   public IList&lt;Contact&gt; Contacts {get; set;}
  }
  
  
  public class Contact
  {
   public string Number {get; set;}
   public string Address { get; set;}
  }
  </code></pre>
  
  <p>I am using Low Level API for <code>DynamoDb</code> CRUD. This is how my method looks like</p>
  
  <pre><code>public async Task&lt;CustomerTO&gt; Add(CustomerTO obj)
      {
          try
          {
  
              var res = await _dynamoClient.PutItemAsync(tableName: _tableName, item: SetObject(obj));
              if (res.HttpStatusCode == System.Net.HttpStatusCode.OK)
              {
                  return obj;
              }
              else
              {
                  //throw new Exception("Error" + res);
              }
          }
          catch (Exception ex)
          {
  
              Logger.Log(ex);
              return null;
          }
      }
  
      private Dictionary&lt;string, AttributeValue&gt; SetObject(CustomerTO obj)
      {
  
  
          //DynamoDb - Using Low Level API
          var attributes = new Dictionary&lt;string,
          AttributeValue&gt; {
              //Id
              {
                  nameof(obj.Id),
                  new AttributeValue {
                      S = obj.Id
                  }
              },
  
              //Name
              {
                  nameof(obj.Name),
                  new AttributeValue {
                      S = obj.Name
                  }
              },
              {
                  nameof(obj.Contacts),
                  new AttributeValue
                  {
                     S = JsonConvert.SerializeObject(obj.Contacts)
                  }
              }
          };
  
          //attributes[nameof(obj.Contacts)] = Document.FromJson(obj.Contacts);
          return attributes;
      }
  </code></pre>
  
  <p>This is storing the Contacts fields as a string with escape characters as</p>
  
  <pre><code>[\r\n  {\r\n    \"Number\": \"a6e8003e-3991-4f0c-a47f-49b26d6d83c0\",\r\n    \"Address\": \"Free\"}]
  </code></pre>
  
  <p>As I am passing as a string so quite obvious it would store as string.</p>
  
  <p>But how do I convert this Contacts as fields so that it is stored as an <code>Array</code>, <code>List (L)</code> or <code>JSON</code> string with no escape characters?</p>
  
  <p>Thanks!</p>