Skip to content

Latest commit

 

History

History
21 lines (17 loc) · 772 Bytes

WriteToJsonFile.md

File metadata and controls

21 lines (17 loc) · 772 Bytes

Write JSON to a file

This sample writes LINQ to JSON objects to a file.

var 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 var file = File.CreateText(@"c:\videogames.json");
using var writer = new JsonTextWriter(file);
videogameRatings.WriteTo(writer);

snippet source | anchor