Click or drag to resize
Json.NETJsonConvert Class
 
Provides methods for converting between common language runtime types and JSON types.
Inheritance Hierarchy
SystemObject
  Newtonsoft.JsonJsonConvert

Namespace: Newtonsoft.Json
Assembly: Newtonsoft.Json (in Newtonsoft.Json.dll) Version: 7.0.0.0 (7.0.1.18406)
Syntax
C#
public static class JsonConvert

The JsonConvert type exposes the following members.

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 memberDeserializeObjectAsync(String) Obsolete.
Asynchronously deserializes the JSON to the specified .NET type. Deserialization will happen on a new thread.
Public methodStatic memberDeserializeObjectAsync(String, Type, JsonSerializerSettings) Obsolete.
Asynchronously deserializes the JSON to the specified .NET type using JsonSerializerSettings. Deserialization will happen on a new thread.
Public methodStatic memberDeserializeObjectAsyncT(String) Obsolete.
Asynchronously deserializes the JSON to the specified .NET type. Deserialization will happen on a new thread.
Public methodStatic memberDeserializeObjectAsyncT(String, JsonSerializerSettings) Obsolete.
Asynchronously deserializes the JSON to the specified .NET type using JsonSerializerSettings. Deserialization will happen on a new thread.
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 elment specified by deserializeRootElementName.
Public methodStatic memberDeserializeXmlNode(String, String, Boolean)
Deserializes the XmlNode from a JSON string nested in a root elment specified by deserializeRootElementName and writes a .NET array attribute for collections.
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 elment specified by deserializeRootElementName.
Public methodStatic memberDeserializeXNode(String, String, Boolean)
Deserializes the XNode from a JSON string nested in a root elment specified by deserializeRootElementName and writes a .NET array attribute for collections.
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 memberPopulateObjectAsync Obsolete.
Asynchronously 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 memberSerializeObjectAsync(Object) Obsolete.
Asynchronously serializes the specified object to a JSON string. Serialization will happen on a new thread.
Public methodStatic memberSerializeObjectAsync(Object, Formatting) Obsolete.
Asynchronously serializes the specified object to a JSON string using formatting. Serialization will happen on a new thread.
Public methodStatic memberSerializeObjectAsync(Object, Formatting, JsonSerializerSettings) Obsolete.
Asynchronously serializes the specified object to a JSON string using formatting and a collection of JsonConverter. Serialization will happen on a new thread.
Public methodStatic memberSerializeXmlNode(XmlNode)
Serializes the XML node to a JSON string.
Public methodStatic memberSerializeXmlNode(XmlNode, Formatting)
Serializes the XML node to a JSON string using formatting.
Public methodStatic memberSerializeXmlNode(XmlNode, Formatting, Boolean)
Serializes the XML node 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
Properties
Examples
Serializing and Deserializing JSON with JsonConvert
 1Product product = new Product();
 2
 3product.Name = "Apple";
 4product.ExpiryDate = new DateTime(2008, 12, 28);
 5product.Price = 3.99M;
 6product.Sizes = new string[] { "Small", "Medium", "Large" };
 7
 8string output = JsonConvert.SerializeObject(product);
 9//{
10//  "Name": "Apple",
11//  "ExpiryDate": "2008-12-28T00:00:00",
12//  "Price": 3.99,
13//  "Sizes": [
14//    "Small",
15//    "Medium",
16//    "Large"
17//  ]
18//}
19
20Product deserializedProduct = JsonConvert.DeserializeObject<Product>(output);
See Also