title: Get all .json Files from a Folder and then serialize in a single .Json File using C# and JSON.Net and Serialize
body: <p>I have many .json file which I stored in a folder. Now I want to get all these .json files to serialize in a single file. Well I am started how to proceed with it but not getting the correct approach of it. My single .json file look like this-</p>
  
  <pre><code>{
        "Name": "Holstentor",
        "Shorttext": "The Holsten Gate is a city gate marking off the western boundary of the old center of the Hanseatic city of Lübeck. This Brick Gothic construction is one of the relics of Lübeck’s medieval city fortifications and one of two remaining city gates, the other being the Citadel Gate  Because its two round towers and arched entrance are so well known it is regarded today as a symbol of this German city, and together with the old city centre of Lübeck it has been a UNESCO World Heritage Site since 1987.\nHolstentor was built in 1464.",
        "GeoCoordinates": {
          "Longitude": 10.6797,
          "Latitude": 53.8662
        },
        "Images": [
          "https://upload.wikimedia.org/wikipedia/commons/thumb/c/ca/Holstentor_in_L%C3%BCbeck_Frontseite_-_Zuschnitt.jpg/378px-Holstentor_in_L%C3%BCbeck_Frontseite_-_Zuschnitt.jpg"
        ]
      }
  </code></pre>
  
  <p>and another .json file </p>
  
  <pre><code>{
            "Name": "Passat (ship)",
            "Shorttext": "Passat is a German four-masted steel barque and one of the Flying P-Liners, the famous sailing ships of the German shipping company F. Laeisz. The name \"Passat\" means trade wind in German. She is one of the last surviving windjammers.",
            "GeoCoordinates": {
              "Longitude": 10.88138889,
              "Latitude": 53.95805556
            },
            "Images": [
              "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d1/Flying_P-Liner_Passat_ship_in_Travem%C3%BCnde.jpg/400px-Flying_P-Liner_Passat_ship_in_Travem%C3%BCnde.jpg"
            ]
          }
  </code></pre>
  
  <p>I have similar .json files 10 or 15 for each place. I stored this files in a folder, the Folder name is the main City name.</p>
  
  <p>Now I want to get all this .json files and serialize them in a single file similar like this-</p>
  
  <p>I have generated c# class for json object in the similar way-</p>
  
  <pre><code> public class GeoCoordinates
   {
   public double Longitude { get; set; }
   public double Latitude { get; set; }
   }
  
  public class Tourist
   {
    public string Name { get; set; }
    public string Shorttext { get; set; }
    public GeoCoordinates GeoCoordinates { get; set; }
    public List&lt;string&gt; Images { get; set; }
   }
  
   public class City
   {
    public List&lt;Tourist&gt; Tourist { get; set; }
   }
  
  public class RootObject
  {
    public List&lt;City&gt; city { get; set; }
  }
  </code></pre>
  
  <p>I stared my coding in this way-</p>
  
  <pre><code> static void Main(string[] args)
      {
          var startPath = Application.StartupPath;
          var cities = new List&lt;City&gt;();
          DirectoryInfo d = new DirectoryInfo(startPath + @"\FinalJson\Flensburg\");
          foreach (var file in d.GetFiles("*.json"))
          {
            using (StreamReader fi = File.OpenText(file.FullName))
            {
              JsonSerializer serializer = new JsonSerializer();
              City city = (City)serializer.Deserialize(fi, typeof(City));
             cities.Add(city);
           }
          }
  
          using (StreamWriter file = File.CreateText(@"c:\cities.json"))
          {
              JsonSerializer serializer = new JsonSerializer();
              serializer.Serialize(file, cities);
          }
  
  
  
      }
  
      public virtual string FullName { get; set; }
  
      static void DisplayFileSystemInfoAttributes(FileSystemInfo fi)
      {
          //  Assume that this entry is a file.
          string entryType = "File";
  
          // Determine if entry is really a directory
          if ((fi.Attributes &amp; FileAttributes.Directory) == FileAttributes.Directory)
          {
              entryType = "Directory";
          }
          //  Show this entry's type, name, and creation date.
          Console.WriteLine("{0} entry {1} was created on {2:D}", entryType, fi.FullName, fi.CreationTime);
      }
  }
  </code></pre>
  
  <p>I want to get my result in this way-</p>
  
  <pre><code>{
  "Kiel": [ //city name
      {
          "Tourist": [
              {
                  "Name": "Holstentor",
                  "Shorttext": "The Holsten Gate is a city gate marking off the western boundary of the old center of the Hanseatic city of Lübeck. This Brick Gothic construction is one of the relics of Lübeck’s medieval city fortifications and one of two remaining city gates, the other being the Citadel Gate  Because its two round towers and arched entrance are so well known it is regarded today as a symbol of this German city, and together with the old city centre of Lübeck it has been a UNESCO World Heritage Site since 1987.\nHolstentor was built in 1464.",
                  "GeoCoordinates": {
                      "Longitude": 10.6797,
                      "Latitude": 53.8662
                  },
                  "Images": [
                      "https://upload.wikimedia.org/wikipedia/commons/thumb/c/ca/Holstentor_in_L%C3%BCbeck_Frontseite_-_Zuschnitt.jpg/378px-Holstentor_in_L%C3%BCbeck_Frontseite_-_Zuschnitt.jpg"
                  ]
              },
   {
                  "Name": "Stadion Lohmühle",
                  "Shorttext": "Das Stadion an der Lohmühle, oder auch einfach nur „Lohmühle“ genannt, ist ein reines Fußballstadion in Lübeck und das größte Stadion in Schleswig-Holstein.\nEs ist die Heimat des VfB Lübeck. Nach Abriss der alten Tribüne und dem Bau der neuen Haupttribüne in den 1990er Jahren im Zuge des Aufstiegs in die 2. Bundesliga im Jahre 1996 fasst das Stadion 17.869 Plätze, darunter etwa 4.400 überdachte Sitzplätze.\n\n",
                  "GeoCoordinates": {
                      "Longitude": 10.66888905,
                      "Latitude": 53.88111115
                  },
                  "Images": [
                      "https://upload.wikimedia.org/wikipedia/commons/thumb/1/1c/L%C3%BCbeck-Lohm%C3%BChle_1.jpg/400px-L%C3%BCbeck-Lohm%C3%BChle_1.jpg"
                  ]
              },
  
     //ans so on ..........
  
          ]
  
      }
    ]
  }
  </code></pre>