Click or drag to resize
Json.NET

JsonConvert Class

 
Provides methods for converting between .NET types and JSON types.
Inheritance Hierarchy
SystemObject
  Newtonsoft.JsonJsonConvert

Namespace:  Newtonsoft.Json
Assembly:  Newtonsoft.Json (in Newtonsoft.Json.dll) Version: 12.0.1+509643a8952ce731e0207710c429ad6e67dc43db
Syntax
C#
public static class JsonConvert

The JsonConvert type exposes the following members.

Properties
Methods
  NameDescription
Public methodStatic memberDeserializeAnonymousTypeT(String, T)
Deserializes the JSON to the given anonymous type.
Public methodStatic memberDeserializeAnonymousTypeT(String, T, JsonSerializerSettings)
Deserializes the JSON to the given anonymous type using JsonSerializerSettings.
Public methodStatic memberDeserializeObject(String)
Deserializes the JSON to a .NET object.
Public methodStatic memberDeserializeObject(String, JsonSerializerSettings)
Deserializes the JSON to a .NET object using JsonSerializerSettings.
Public methodStatic memberDeserializeObject(String, Type)
Deserializes the JSON to the specified .NET type.
Public methodStatic memberDeserializeObject(String, Type, JsonConverter)
Deserializes the JSON to the specified .NET type using a collection of JsonConverter.
Public methodStatic memberDeserializeObject(String, Type, JsonSerializerSettings)
Deserializes the JSON to the specified .NET type using JsonSerializerSettings.
Public methodStatic memberDeserializeObjectT(String)
Deserializes the JSON to the specified .NET type.
Public methodStatic memberDeserializeObjectT(String, JsonConverter)
Deserializes the JSON to the specified .NET type using a collection of JsonConverter.
Public methodStatic memberDeserializeObjectT(String, JsonSerializerSettings)
Deserializes the JSON to the specified .NET type using JsonSerializerSettings.
Public methodStatic memberDeserializeXmlNode(String)
Deserializes the XmlNode from a JSON string.
Public methodStatic memberDeserializeXmlNode(String, String)
Deserializes the XmlNode from a JSON string nested in a root element specified by deserializeRootElementName.
Public methodStatic memberDeserializeXmlNode(String, String, Boolean)
Deserializes the XmlNode from a JSON string nested in a root element specified by deserializeRootElementName and writes a Json.NET array attribute for collections.
Public methodStatic memberDeserializeXmlNode(String, String, Boolean, Boolean)
Deserializes the XmlNode from a JSON string nested in a root element specified by deserializeRootElementName, writes a Json.NET array attribute for collections, and encodes special characters.
Public methodStatic memberDeserializeXNode(String)
Deserializes the XNode from a JSON string.
Public methodStatic memberDeserializeXNode(String, String)
Deserializes the XNode from a JSON string nested in a root element specified by deserializeRootElementName.
Public methodStatic memberDeserializeXNode(String, String, Boolean)
Deserializes the XNode from a JSON string nested in a root element specified by deserializeRootElementName and writes a Json.NET array attribute for collections.
Public methodStatic memberDeserializeXNode(String, String, Boolean, Boolean)
Deserializes the XNode from a JSON string nested in a root element specified by deserializeRootElementName, writes a Json.NET array attribute for collections, and encodes special characters.
Public methodStatic memberPopulateObject(String, Object)
Populates the object with values from the JSON string.
Public methodStatic memberPopulateObject(String, Object, JsonSerializerSettings)
Populates the object with values from the JSON string using JsonSerializerSettings.
Public methodStatic memberSerializeObject(Object)
Serializes the specified object to a JSON string.
Public methodStatic memberSerializeObject(Object, Formatting)
Serializes the specified object to a JSON string using formatting.
Public methodStatic memberSerializeObject(Object, JsonConverter)
Serializes the specified object to a JSON string using a collection of JsonConverter.
Public methodStatic memberSerializeObject(Object, JsonSerializerSettings)
Serializes the specified object to a JSON string using JsonSerializerSettings.
Public methodStatic memberSerializeObject(Object, Formatting, JsonConverter)
Serializes the specified object to a JSON string using formatting and a collection of JsonConverter.
Public methodStatic memberSerializeObject(Object, Formatting, JsonSerializerSettings)
Serializes the specified object to a JSON string using formatting and JsonSerializerSettings.
Public methodStatic memberSerializeObject(Object, Type, JsonSerializerSettings)
Serializes the specified object to a JSON string using a type, formatting and JsonSerializerSettings.
Public methodStatic memberSerializeObject(Object, Type, Formatting, JsonSerializerSettings)
Serializes the specified object to a JSON string using a type, formatting and JsonSerializerSettings.
Public methodStatic memberSerializeXmlNode(XmlNode)
Serializes the XmlNode to a JSON string.
Public methodStatic memberSerializeXmlNode(XmlNode, Formatting)
Serializes the XmlNode to a JSON string using formatting.
Public methodStatic memberSerializeXmlNode(XmlNode, Formatting, Boolean)
Serializes the XmlNode to a JSON string using formatting and omits the root object if omitRootObject is true.
Public methodStatic memberSerializeXNode(XObject)
Serializes the XNode to a JSON string.
Public methodStatic memberSerializeXNode(XObject, Formatting)
Serializes the XNode to a JSON string using formatting.
Public methodStatic memberSerializeXNode(XObject, Formatting, Boolean)
Serializes the XNode to a JSON string using formatting and omits the root object if omitRootObject is true.
Public methodStatic memberToString(Boolean)
Converts the Boolean to its JSON string representation.
Public methodStatic memberToString(Byte)
Converts the Byte to its JSON string representation.
Public methodStatic memberToString(Char)
Converts the Char to its JSON string representation.
Public methodStatic memberToString(DateTime)
Converts the DateTime to its JSON string representation.
Public methodStatic memberToString(DateTimeOffset)
Converts the DateTimeOffset to its JSON string representation.
Public methodStatic memberToString(Decimal)
Converts the Decimal to its JSON string representation.
Public methodStatic memberToString(Double)
Converts the Double to its JSON string representation.
Public methodStatic memberToString(Enum)
Converts the Enum to its JSON string representation.
Public methodStatic memberToString(Guid)
Converts the Guid to its JSON string representation.
Public methodStatic memberToString(Int16)
Converts the Int16 to its JSON string representation.
Public methodStatic memberToString(Int32)
Converts the Int32 to its JSON string representation.
Public methodStatic memberToString(Int64)
Converts the Int64 to its JSON string representation.
Public methodStatic memberToString(Object)
Converts the Object to its JSON string representation.
Public methodStatic memberToString(SByte)
Converts the SByte to its JSON string representation.
Public methodStatic memberToString(Single)
Converts the Single to its JSON string representation.
Public methodStatic memberToString(String)
Converts the String to its JSON string representation.
Public methodStatic memberToString(TimeSpan)
Converts the TimeSpan to its JSON string representation.
Public methodStatic memberToString(UInt16)
Converts the UInt16 to its JSON string representation.
Public methodStatic memberToString(UInt32)
Converts the UInt32 to its JSON string representation.
Public methodStatic memberToString(UInt64)
Converts the UInt64 to its JSON string representation.
Public methodStatic memberToString(Uri)
Converts the Uri to its JSON string representation.
Public methodStatic memberToString(DateTimeOffset, DateFormatHandling)
Converts the DateTimeOffset to its JSON string representation using the DateFormatHandling specified.
Public methodStatic memberToString(String, Char)
Converts the String to its JSON string representation.
Public methodStatic memberToString(DateTime, DateFormatHandling, DateTimeZoneHandling)
Converts the DateTime to its JSON string representation using the DateFormatHandling specified.
Public methodStatic memberToString(String, Char, StringEscapeHandling)
Converts the String to its JSON string representation.
Top
Fields
  NameDescription
Public fieldStatic memberFalse
Represents JavaScript's boolean value false as a string. This field is read-only.
Public fieldStatic memberNaN
Represents JavaScript's NaN as a string. This field is read-only.
Public fieldStatic memberNegativeInfinity
Represents JavaScript's negative infinity as a string. This field is read-only.
Public fieldStatic memberNull
Represents JavaScript's null as a string. This field is read-only.
Public fieldStatic memberPositiveInfinity
Represents JavaScript's positive infinity as a string. This field is read-only.
Public fieldStatic memberTrue
Represents JavaScript's boolean value true as a string. This field is read-only.
Public fieldStatic memberUndefined
Represents JavaScript's undefined as a string. This field is read-only.
Top
Examples
Serializing and Deserializing JSON with JsonConvert
Product product = new Product();

product.Name = "Apple";
product.ExpiryDate = new DateTime(2008, 12, 28);
product.Price = 3.99M;
product.Sizes = new string[] { "Small", "Medium", "Large" };

string output = JsonConvert.SerializeObject(product);
//{
//  "Name": "Apple",
//  "ExpiryDate": "2008-12-28T00:00:00",
//  "Price": 3.99,
//  "Sizes": [
//    "Small",
//    "Medium",
//    "Large"
//  ]
//}

Product deserializedProduct = JsonConvert.DeserializeObject<Product>(output);
See Also