How do I turn a C# object into a JSON string in .NET?

Since we all love one-liners

… this one depends on the Newtonsoft NuGet package, which is popular and better than the default serializer.

Newtonsoft.Json.JsonConvert.SerializeObject(new {foo = "bar"})

Documentation: Serializing and Deserializing JSON

Leave a Comment