To create a JSON file in C# you can use the Newtonsoft.Json library which provides easy serialization and deserialization of JSON. Below is some code to create a JSON file using a Dictionary<string, object>
data structure and save it to a file.
main.cs425 chars15 lines
This code example creates a dictionary data structure data
with two key-value pairs. It then uses the JsonConvert.SerializeObject()
method to serialize the data into a JSON string with indentation for readability. Finally, the File.WriteAllText()
method is used to write the JSON string to a file named data.json
in the current working directory.
gistlibby LogSnag