How to export an object as json file in C#

Valérie Gelbgras
Valérie Gelbgras Member, Employee Posts: 157
First Answer Solution Developer Community of Practice Member 5 Likes Ansys Employee
✭✭✭✭

How to export an object as json file in C#

Tagged:

Answers

  • Valérie Gelbgras
    Valérie Gelbgras Member, Employee Posts: 157
    First Answer Solution Developer Community of Practice Member 5 Likes Ansys Employee
    ✭✭✭✭
    Answer ✓

    Here is an example

    using (StreamWriter file = File.CreateText(@"c:\test.json"))
    {
        JsonSerializer serializer = new JsonSerializer();
        serializer.Serialize(file, modelObject);
     }