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
More Related Contents:
- Deserialize JSON into C# dynamic object?
- How to deserialize an array of values with a fixed schema to a strongly typed data class?
- Getting ServiceStack to retain type information
- Detect if deserialized object is missing a field with the JsonConvert class in Json.NET
- How to serialize/deserialize a custom collection with additional properties using Json.Net
- Custom Deserialization using Json.NET
- C# automatic property deserialization of JSON
- Cannot deserialize JSON array into type – Json.NET
- How to apply indenting serialization only to some properties?
- Ignoring a field during .NET JSON serialization; similar to [XmlIgnore]?
- Ignoring null fields in Json.net
- Can JavaScriptSerializer exclude properties with null/default values?
- How to serialize or deserialize a JSON Object to a certain depth in C#?
- Deserializing JSON into an object with Json.NET
- Remove empty string properties from json serialized object
- How do I get formatted JSON in .NET using C#?
- A circular reference was detected while serializing an object of type ‘SubSonic.Schema .DatabaseColumn’.
- Newtonsoft.JSON cannot convert model with TypeConverter attribute
- C# JSON Serialization of Dictionary into {key:value, …} instead of {key:key, value:value, …}
- EF 4.1 – Code First – JSON Circular Reference Serialization Error
- Deserializing XML to Objects in C#
- Serialize Property, but Do Not Deserialize Property in Json.Net
- Is it possible to do .NET binary serialization of an object when you don’t have the source code of the class?
- XmlSerializer – There was an error reflecting type
- JSON Serializer object with internal properties
- JSON Serialize List
- End of Stream encountered before parsing was completed?
- How to save shapes which I draw on a Panel as binary
- How do I get formatted and indented JSON in .NET using C#?
- Parsing field name with a colon in JSON