JavaScriptSerializer Class


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Json.NET should be used serialization and deserialization. Provides serialization and deserialization functionality for AJAX-enabled applications.

Namespace:   System.Web.Script.Serialization
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)


public ref class JavaScriptSerializer 


Initializes a new instance of the JavaScriptSerializer class that has no type resolver.


Initializes a new instance of the JavaScriptSerializer class that has a custom type resolver.


Gets or sets the maximum length of JSON strings that are accepted by the JavaScriptSerializer class.


Gets or sets the limit for constraining the number of object levels to process.

System_CAPS_pubmethodConvertToType(Object^, Type^)

Converts the specified object to the specified type.


Converts the given object to the specified type.

System_CAPS_pubmethodDeserialize(String^, Type^)

Converts a JSON-formatted string to an object of the specified type.


Converts the specified JSON string to an object of type T.


Converts the specified JSON string to an object graph.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Creates a shallow copy of the current Object.(Inherited from Object.)


Registers a custom converter with the JavaScriptSerializer instance.


Converts an object to a JSON string.

System_CAPS_pubmethodSerialize(Object^, StringBuilder^)

Serializes an object and writes the resulting JSON string to the specified StringBuilder object.


Returns a string that represents the current object.(Inherited from Object.)

The JavaScriptSerializer class is used internally by the asynchronous communication layer to serialize and deserialize the data that is passed between the browser and the Web server. You cannot access that instance of the serializer. However, this class exposes a public API. Therefore, you can use the class when you want to work with JavaScript Object Notation (JSON) in managed code.

To serialize an object, use the Serialize method. To deserialize a JSON string, use the Deserialize<T> or DeserializeObject methods. To serialize and deserialize types that are not natively supported by JavaScriptSerializer, implement custom converters by using the JavaScriptConverter class. Then register the converters by using the RegisterConverters method.

The following table shows the mapping between managed types and JSON for the serialization process. These managed types are natively supported by JavaScriptSerializer. When you are deserializing from a JSON string to a managed type, the same mapping applies. However, deserialization can be asymmetric; not all serializable managed types can be deserialized from JSON.


A multidimensional array is serialized as a one-dimensional array, and you should use it as a flat array.

Managed type

JSON equivalent

String (UTF-8 encoding only).




Single null char (such as, \0 )



Boolean. Represented in JSON as true or false

null (null object references and Nullable value types).

A string value of null


A string value of null

Primitive numeric (or numeric-compatible) types: Byte, SByte, Int16, Int32, Int64, UInt16, UInt32, UInt64, Double, and Single. The culture-invariant string representation is used.



Date object, represented in JSON as "\/Date(number of ticks)\/". The number of ticks is a positive or negative long value that indicates the number of ticks (milliseconds) that have elapsed since midnight 01 January, 1970 UTC.

The maximum supported date value is MaxValue (12/31/9999 11:59:59 PM) and the minimum supported date value is MinValue (1/1/0001 12:00:00 AM).

Enumerations of integer type

Integer equivalent of the enumeration value

Types that implement IEnumerable or System.Collections.Generic::IEnumerable<T> that are not also implementations of IDictionary or System.Collections.Generic::IDictionary<TKey, TValue>. This includes types such as Array, ArrayList, and List<T>.

Array that uses JSON array syntax

Types that implement IDictionary or System.Collections.Generic::IDictionary<TKey, TValue>. This includes types such as Dictionary<TKey, TValue> and Hashtable.

JavaScript object that uses JSON dictionary syntax

Custom concrete (non-abstract) types that have public instance properties that have get accessors or public instance fields.

Note that public write-only properties, public property or public field attributes marked with ScriptIgnoreAttribute, and public indexed properties in these types are ignored.

JavaScript object that uses JSON dictionary syntax. A special metadata property named "__type" is included to ensure correct deserialization. Make sure that public instance properties have get and set accessors to ensure correct deserialization.


String representation of a GUID


String representation of the return value of GetComponents

The first example provides a simple illustration of how to serialize and deserialize data objects. It requires a class names Person which is shown below.

No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.

The next example shows a more complicated and complete project that uses the JavaScriptSerializer class to save and restore the state of an object by using JSON serialization. This code uses a custom converter that is provided for the JavaScriptConverter class.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 3.5

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

System.Web.Script.Serialization Namespace
Using Web Services in ASP.NET AJAX
Calling Web Services from Client Script in ASP.NET AJAX

Return to top