title: Replicating a JSON file in C#
body: <p>For a project that I am working on, I'm trying to replicate a JSON file that was created with JavaScript in C#. For this project I have to label images before I can run them through a Neural Network, and to annotate those images I use <a href="http://www.robots.ox.ac.uk/%7Evgg/software/via/" rel="nofollow noreferrer">via</a>. The resulting JSON file looks like this.</p>
  <pre class="lang-json prettyprint-override"><code>&quot;Dog.png173732&quot;: {
      &quot;filename&quot;: &quot;Dog.png&quot;,
      &quot;size&quot;: 173732,
      &quot;regions&quot;: [
          {
              &quot;shape_attributes&quot;: {
                  &quot;name&quot;: &quot;polygon&quot;,
                  &quot;all_points_x&quot;: [
                      189,
                      192,
                      229,
                      230
                  ],
                  &quot;all_points_y&quot;: [
                      2,
                      148,
                      148,
                      2
                  ]
              },
              &quot;region_attributes&quot;: {
                  &quot;Animal&quot;: &quot;Dog&quot;
              }
          }
      ],
      &quot;file_attributes&quot;: {}
  },
  </code></pre>
  <p>To replicate this in C#, I created a class with multiple getters and setters, while using the Nuget package <a href="https://www.newtonsoft.com/json" rel="nofollow noreferrer">JSON.Net</a>, to serialize my JSON.</p>
  <pre class="lang-cs prettyprint-override"><code>public class Animal
  {
      [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
      public string Filename { get; set; }
      [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
      public int? Size { get; set; }
      [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
      public List&lt;Animal&gt; Regions { get; set; }
      [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
      public List&lt;Animal&gt; Shape_attributes { get; set; }
      [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
      public string Name { get; set; }
      [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
      public List&lt;int&gt; All_points_x { get; set; }
      [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
      public List&lt;int&gt; All_points_y { get; set; }
      [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
      public List&lt;Animal&gt; Region_attributes { get; set; }
      [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
      public string Animal { get; set; }
  
  
      public void CreateJSON()
      {
          string output = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) +
              @&quot;\source\repos\Testing\&quot;;
  
          var root = new Animal()
          {
              Filename = &quot;Dog.png&quot;,
              Size = 173732,
              Regions = new List&lt;Animal&gt;()
              {
                  new Animal()
                  {
                      Size = null,
  
                      Shape_attributes = new List&lt;Animal&gt;()
                      {
                          new Animal()
                          {
                              Name = &quot;polygon&quot;,
                              All_points_x = All_points_x,
                              All_points_y = All_points_y
                          }
                      },
  
                      Region_attributes = new List&lt;Animal&gt;()
                      {
                          new Animal()
                          {
                              Animal = &quot;Dog&quot;
                          }
                      }
                  }
              }
          };
  
          var json = JsonConvert.SerializeObject(root, new JsonSerializerSettings
          {
              ContractResolver = new CamelCasePropertyNamesContractResolver()
          });
  
          File.WriteAllText(output + &quot;testing.json&quot;, json);
      }
  </code></pre>
  <p>Once I execute the following code, my output is as follows.</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;filename&quot;: &quot;Dog.png&quot;,
      &quot;size&quot;: 173732,
      &quot;regions&quot;: [
          {
              &quot;shape_attributes&quot;: [
                  {
                      &quot;name&quot;: &quot;polygon&quot;,
                      &quot;all_points_x&quot;: [
                          389,
                          43
                      ],
                      &quot;all_points_y&quot;: [
                          33,
                          215
                      ]
                  }
              ],
              &quot;region_attributes&quot;: [
                  {
                      &quot;animal&quot;: &quot;Dog&quot;
                  }
              ]
          }
      ]
  }
  </code></pre>
  <p>How can I adjust my code to better replicated via's Json file? Is there a better way that I could be doing things?</p>