1. [DataContract]
    2. public class File
    3. {
    4. // excluded from serialization
    5. // does not have DataMemberAttribute
    6. public Guid Id { get; set; }
    7. [DataMember]
    8. public string Name { get; set; }
    9. [DataMember]
    10. public int Size { get; set; }
    11. }
    12. File file = new File
    13. {
    14. Id = Guid.NewGuid(),
    15. Name = "ImportantLegalDocuments.docx",
    16. Size = 50 * 1024
    17. };
    18. string json = JsonConvert.SerializeObject(file, Formatting.Indented);
    19. Console.WriteLine(json);
    20. // {
    21. // "Name": "ImportantLegalDocuments.docx",
    22. // "Size": 51200
    23. // }