Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class Newtonsoft.​Json.​JsonConvert

Assembly: Newtonsoft.Json

Inheritance: object → JsonConvert

Provides methods for converting between .NET types and JSON types.

Fields and Constants

public static readonly string
True
Represents JavaScript's boolean value <c>true</c> as a string. This field is read-only.
public static readonly string
False
Represents JavaScript's boolean value <c>false</c> as a string. This field is read-only.
public static readonly string
Null
Represents JavaScript's <c>null</c> as a string. This field is read-only.
public static readonly string
Undefined
Represents JavaScript's <c>undefined</c> as a string. This field is read-only.
public static readonly string
PositiveInfinity
Represents JavaScript's positive infinity as a string. This field is read-only.
public static readonly string
NegativeInfinity
Represents JavaScript's negative infinity as a string. This field is read-only.
public static readonly string
NaN
Represents JavaScript's <c>NaN</c> as a string. This field is read-only.

Properties

DefaultSettings
Gets or sets a function that creates default <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> . Default settings are automatically used by serialization methods on <see cref="T:Newtonsoft.Json.JsonConvert" /> , and <see cref="M:Newtonsoft.Json.Linq.JToken.ToObject``1" /> and <see cref="M:Newtonsoft.Json.Linq.JToken.FromObject(System.Object)" /> on <see cref="T:Newtonsoft.Json.Linq.JToken" /> . To serialize without using any default settings create a <see cref="T:Newtonsoft.Json.JsonSerializer" /> with <see cref="M:Newtonsoft.Json.JsonSerializer.Create" /> .

Methods

public static string
ToString​(System.​DateTime value)
Converts the <see cref="T:System.DateTime" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.DateTime" /> .
value The value to convert.
public static string
ToString​(System.​DateTime value, DateFormatHandling format, DateTimeZoneHandling timeZoneHandling)
Converts the <see cref="T:System.DateTime" /> to its JSON string representation using the <see cref="T:Newtonsoft.Json.DateFormatHandling" /> specified.
Returns A JSON string representation of the <see cref="T:System.DateTime" /> .
value The value to convert.
format The format the date will be converted to.
timeZoneHandling The time zone handling when the date is converted to a string.
public static string
ToString​(System.​DateTimeOffset value)
Converts the <see cref="T:System.DateTimeOffset" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.DateTimeOffset" /> .
value The value to convert.
public static string
ToString​(System.​DateTimeOffset value, DateFormatHandling format)
Converts the <see cref="T:System.DateTimeOffset" /> to its JSON string representation using the <see cref="T:Newtonsoft.Json.DateFormatHandling" /> specified.
Returns A JSON string representation of the <see cref="T:System.DateTimeOffset" /> .
value The value to convert.
format The format the date will be converted to.
public static string
ToString​(bool value)
Converts the <see cref="T:System.Boolean" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.Boolean" /> .
value The value to convert.
public static string
ToString​(char value)
Converts the <see cref="T:System.Char" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.Char" /> .
value The value to convert.
public static string
ToString​(System.​Enum value)
Converts the <see cref="T:System.Enum" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.Enum" /> .
value The value to convert.
public static string
ToString​(int value)
Converts the <see cref="T:System.Int32" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.Int32" /> .
value The value to convert.
public static string
ToString​(short value)
Converts the <see cref="T:System.Int16" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.Int16" /> .
value The value to convert.
public static string
ToString​(ushort value)
Converts the <see cref="T:System.UInt16" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.UInt16" /> .
value The value to convert.
public static string
ToString​(uint value)
Converts the <see cref="T:System.UInt32" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.UInt32" /> .
value The value to convert.
public static string
ToString​(long value)
Converts the <see cref="T:System.Int64" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.Int64" /> .
value The value to convert.
public static string
ToString​(ulong value)
Converts the <see cref="T:System.UInt64" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.UInt64" /> .
value The value to convert.
public static string
ToString​(System.​Single value)
Converts the <see cref="T:System.Single" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.Single" /> .
value The value to convert.
public static string
ToString​(double value)
Converts the <see cref="T:System.Double" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.Double" /> .
value The value to convert.
public static string
ToString​(byte value)
Converts the <see cref="T:System.Byte" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.Byte" /> .
value The value to convert.
public static string
ToString​(sbyte value)
Converts the <see cref="T:System.SByte" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.SByte" /> .
value The value to convert.
public static string
ToString​(decimal value)
Converts the <see cref="T:System.Decimal" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.SByte" /> .
value The value to convert.
public static string
ToString​(System.​Guid value)
Converts the <see cref="T:System.Guid" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.Guid" /> .
value The value to convert.
public static string
ToString​(System.​TimeSpan value)
Converts the <see cref="T:System.TimeSpan" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.TimeSpan" /> .
value The value to convert.
public static string
ToString​(System.​Uri value)
Converts the <see cref="T:System.Uri" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.Uri" /> .
value The value to convert.
public static string
ToString​(string value)
Converts the <see cref="T:System.String" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.String" /> .
value The value to convert.
public static string
ToString​(string value, char delimiter)
Converts the <see cref="T:System.String" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.String" /> .
value The value to convert.
delimiter The string delimiter character.
public static string
ToString​(string value, char delimiter, StringEscapeHandling stringEscapeHandling)
Converts the <see cref="T:System.String" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.String" /> .
value The value to convert.
delimiter The string delimiter character.
stringEscapeHandling The string escape handling.
public static string
ToString​(object value)
Converts the <see cref="T:System.Object" /> to its JSON string representation.
Returns A JSON string representation of the <see cref="T:System.Object" /> .
value The value to convert.
public static string
SerializeObject​(object value)
Serializes the specified object to a JSON string.
Returns A JSON string representation of the object.
value The object to serialize.
public static string
SerializeObject​(object value, Formatting formatting)
Serializes the specified object to a JSON string using formatting.
Returns A JSON string representation of the object.
value The object to serialize.
formatting Indicates how the output should be formatted.
public static string
SerializeObject​(object value, JsonConverter[] converters)
Serializes the specified object to a JSON string using a collection of <see cref="T:Newtonsoft.Json.JsonConverter" /> .
Returns A JSON string representation of the object.
value The object to serialize.
converters A collection of converters used while serializing.
public static string
SerializeObject​(object value, Formatting formatting, JsonConverter[] converters)
Serializes the specified object to a JSON string using formatting and a collection of <see cref="T:Newtonsoft.Json.JsonConverter" /> .
Returns A JSON string representation of the object.
value The object to serialize.
formatting Indicates how the output should be formatted.
converters A collection of converters used while serializing.
public static string
SerializeObject​(object value, JsonSerializerSettings settings)
Serializes the specified object to a JSON string using <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> .
Returns A JSON string representation of the object.
value The object to serialize.
settings The <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> used to serialize the object. If this is <c>null</c> , default serialization settings will be used.
public static string
SerializeObject​(object value, System.​Type type, JsonSerializerSettings settings)
Serializes the specified object to a JSON string using a type, formatting and <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> .
Returns A JSON string representation of the object.
value The object to serialize.
type The type of the value being serialized. This parameter is used when <see cref="P:Newtonsoft.Json.JsonSerializer.TypeNameHandling" /> is <see cref="F:Newtonsoft.Json.TypeNameHandling.Auto" /> to write out the type name if the type of the value does not match. Specifying the type is optional.
settings The <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> used to serialize the object. If this is <c>null</c> , default serialization settings will be used.
public static string
SerializeObject​(object value, Formatting formatting, JsonSerializerSettings settings)
Serializes the specified object to a JSON string using formatting and <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> .
Returns A JSON string representation of the object.
value The object to serialize.
formatting Indicates how the output should be formatted.
settings The <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> used to serialize the object. If this is <c>null</c> , default serialization settings will be used.
public static string
SerializeObject​(object value, System.​Type type, Formatting formatting, JsonSerializerSettings settings)
Serializes the specified object to a JSON string using a type, formatting and <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> .
Returns A JSON string representation of the object.
value The object to serialize.
type The type of the value being serialized. This parameter is used when <see cref="P:Newtonsoft.Json.JsonSerializer.TypeNameHandling" /> is <see cref="F:Newtonsoft.Json.TypeNameHandling.Auto" /> to write out the type name if the type of the value does not match. Specifying the type is optional.
formatting Indicates how the output should be formatted.
settings The <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> used to serialize the object. If this is <c>null</c> , default serialization settings will be used.
public static object
DeserializeObject​(string value)
Deserializes the JSON to a .NET object.
Returns The deserialized object from the JSON string.
value The JSON to deserialize.
public static object
DeserializeObject​(string value, JsonSerializerSettings settings)
Deserializes the JSON to a .NET object using <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> .
Returns The deserialized object from the JSON string.
value The JSON to deserialize.
settings The <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> used to deserialize the object. If this is <c>null</c> , default serialization settings will be used.
public static object
DeserializeObject​(string value, System.​Type type)
Deserializes the JSON to the specified .NET type.
Returns The deserialized object from the JSON string.
value The JSON to deserialize.
type The <see cref="T:System.Type" /> of object being deserialized.
public static T
DeserializeObject​(string value)
Deserializes the JSON to the specified .NET type.
Returns The deserialized object from the JSON string.
value The JSON to deserialize.
public static T
DeserializeAnonymousType​(string value, T anonymousTypeObject)
Deserializes the JSON to the given anonymous type.
Returns The deserialized anonymous type from the JSON string.
value The JSON to deserialize.
anonymousTypeObject The anonymous type object.
public static T
DeserializeAnonymousType​(string value, T anonymousTypeObject, JsonSerializerSettings settings)
Deserializes the JSON to the given anonymous type using <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> .
Returns The deserialized anonymous type from the JSON string.
value The JSON to deserialize.
anonymousTypeObject The anonymous type object.
settings The <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> used to deserialize the object. If this is <c>null</c> , default serialization settings will be used.
public static T
DeserializeObject​(string value, JsonConverter[] converters)
Deserializes the JSON to the specified .NET type using a collection of <see cref="T:Newtonsoft.Json.JsonConverter" /> .
Returns The deserialized object from the JSON string.
value The JSON to deserialize.
converters Converters to use while deserializing.
public static T
DeserializeObject​(string value, JsonSerializerSettings settings)
Deserializes the JSON to the specified .NET type using <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> .
Returns The deserialized object from the JSON string.
value The object to deserialize.
settings The <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> used to deserialize the object. If this is <c>null</c> , default serialization settings will be used.
public static object
DeserializeObject​(string value, System.​Type type, JsonConverter[] converters)
Deserializes the JSON to the specified .NET type using a collection of <see cref="T:Newtonsoft.Json.JsonConverter" /> .
Returns The deserialized object from the JSON string.
value The JSON to deserialize.
type The type of the object to deserialize.
converters Converters to use while deserializing.
public static object
DeserializeObject​(string value, System.​Type type, JsonSerializerSettings settings)
Deserializes the JSON to the specified .NET type using <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> .
Returns The deserialized object from the JSON string.
value The JSON to deserialize.
type The type of the object to deserialize to.
settings The <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> used to deserialize the object. If this is <c>null</c> , default serialization settings will be used.
public static void
PopulateObject​(string value, object target)
Populates the object with values from the JSON string.
value The JSON to populate values from.
target The target object to populate values onto.
public static void
PopulateObject​(string value, object target, JsonSerializerSettings settings)
Populates the object with values from the JSON string using <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> .
value The JSON to populate values from.
target The target object to populate values onto.
settings The <see cref="T:Newtonsoft.Json.JsonSerializerSettings" /> used to deserialize the object. If this is <c>null</c> , default serialization settings will be used.
public static string
SerializeXmlNode​(System.​Xml.​XmlNode node)
Serializes the <see cref="T:System.Xml.XmlNode" /> to a JSON string.
Returns A JSON string of the <see cref="T:System.Xml.XmlNode" /> .
node The node to serialize.
public static string
SerializeXmlNode​(System.​Xml.​XmlNode node, Formatting formatting)
Serializes the <see cref="T:System.Xml.XmlNode" /> to a JSON string using formatting.
Returns A JSON string of the <see cref="T:System.Xml.XmlNode" /> .
node The node to serialize.
formatting Indicates how the output should be formatted.
public static string
SerializeXmlNode​(System.​Xml.​XmlNode node, Formatting formatting, bool omitRootObject)
Serializes the <see cref="T:System.Xml.XmlNode" /> to a JSON string using formatting and omits the root object if <paramref name="omitRootObject" /> is <c>true</c> .
Returns A JSON string of the <see cref="T:System.Xml.XmlNode" /> .
node The node to serialize.
formatting Indicates how the output should be formatted.
omitRootObject Omits writing the root object.
DeserializeXmlNode​(string value)
Deserializes the <see cref="T:System.Xml.XmlNode" /> from a JSON string.
Returns The deserialized <see cref="T:System.Xml.XmlNode" /> .
value The JSON string.
DeserializeXmlNode​(string value, string deserializeRootElementName)
Deserializes the <see cref="T:System.Xml.XmlNode" /> from a JSON string nested in a root element specified by <paramref name="deserializeRootElementName" /> .
Returns The deserialized <see cref="T:System.Xml.XmlNode" /> .
value The JSON string.
deserializeRootElementName The name of the root element to append when deserializing.
DeserializeXmlNode​(string value, string deserializeRootElementName, bool writeArrayAttribute)
Deserializes the <see cref="T:System.Xml.XmlNode" /> from a JSON string nested in a root element specified by <paramref name="deserializeRootElementName" /> and writes a Json.NET array attribute for collections.
Returns The deserialized <see cref="T:System.Xml.XmlNode" /> .
value The JSON string.
deserializeRootElementName The name of the root element to append when deserializing.
writeArrayAttribute A flag to indicate whether to write the Json.NET array attribute. This attribute helps preserve arrays when converting the written XML back to JSON.
public static string
SerializeXNode​(System.​Xml.​Linq.​XObject node)
Serializes the <see cref="T:System.Xml.Linq.XNode" /> to a JSON string.
Returns A JSON string of the <see cref="T:System.Xml.Linq.XNode" /> .
node The node to convert to JSON.
public static string
SerializeXNode​(System.​Xml.​Linq.​XObject node, Formatting formatting)
Serializes the <see cref="T:System.Xml.Linq.XNode" /> to a JSON string using formatting.
Returns A JSON string of the <see cref="T:System.Xml.Linq.XNode" /> .
node The node to convert to JSON.
formatting Indicates how the output should be formatted.
public static string
SerializeXNode​(System.​Xml.​Linq.​XObject node, Formatting formatting, bool omitRootObject)
Serializes the <see cref="T:System.Xml.Linq.XNode" /> to a JSON string using formatting and omits the root object if <paramref name="omitRootObject" /> is <c>true</c> .
Returns A JSON string of the <see cref="T:System.Xml.Linq.XNode" /> .
node The node to serialize.
formatting Indicates how the output should be formatted.
omitRootObject Omits writing the root object.
DeserializeXNode​(string value)
Deserializes the <see cref="T:System.Xml.Linq.XNode" /> from a JSON string.
Returns The deserialized <see cref="T:System.Xml.Linq.XNode" /> .
value The JSON string.
DeserializeXNode​(string value, string deserializeRootElementName)
Deserializes the <see cref="T:System.Xml.Linq.XNode" /> from a JSON string nested in a root element specified by <paramref name="deserializeRootElementName" /> .
Returns The deserialized <see cref="T:System.Xml.Linq.XNode" /> .
value The JSON string.
deserializeRootElementName The name of the root element to append when deserializing.
DeserializeXNode​(string value, string deserializeRootElementName, bool writeArrayAttribute)
Deserializes the <see cref="T:System.Xml.Linq.XNode" /> from a JSON string nested in a root element specified by <paramref name="deserializeRootElementName" /> and writes a Json.NET array attribute for collections.
Returns The deserialized <see cref="T:System.Xml.Linq.XNode" /> .
value The JSON string.
deserializeRootElementName The name of the root element to append when deserializing.
writeArrayAttribute A flag to indicate whether to write the Json.NET array attribute. This attribute helps preserve arrays when converting the written XML back to JSON.
public bool
Equals​(object obj)
Inherited from object
protected void
Finalize​()
Inherited from object
public int
GetHashCode​()
Inherited from object
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object
public string
ToString​()
Inherited from object