Click or drag to resize
Json.NET

Write JSON to a file

 

This sample writes LINQ to JSON objects to a file.

Sample
Usage
JObject videogameRatings = new JObject(
    new JProperty("Halo", 9),
    new JProperty("Starcraft", 9),
    new JProperty("Call of Duty", 7.5));

File.WriteAllText(@"c:\videogames.json", videogameRatings.ToString());

// write JSON directly to a file
using (StreamWriter file = File.CreateText(@"c:\videogames.json"))
using (JsonTextWriter writer = new JsonTextWriter(file))
{
    videogameRatings.WriteTo(writer);
}