This documentation is archived and is not being maintained.

ScriptIgnoreAttribute Class

Specifies that JavaScriptSerializer will not serialize the public property or public field. This class cannot be inherited.

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

[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class ScriptIgnoreAttribute : Attribute

If you apply ScriptIgnoreAttribute to a public property or public field of a class, then JavaScriptSerializer ignores, or skips, the member when serializing an instance of the class to JavaScript Object Notation (JSON) format.

The ScriptIgnoreAttribute will have no effect if the ResponseFormat property is set to Xml. If you want to have the same behavior when serializing to XML format, XmlIgnoreAttribute should be applied to the property or field instead. This is because the class will be serialized by using XmlSerializer instead of JavaScriptSerializer.

You can also apply both ScriptIgnoreAttribute and XmlIgnoreAttribute to a property or field. In this case, the property or field will be ignored for JSON and XML response formats.

For more information about how to use attributes, see Extending Metadata Using Attributes.

The following example demonstrates how to apply ScriptIgnoreAttribute to the Comment field in the custom class named Group. This instructs JavaScriptSerializer to ignore the field when serializing an instance of the class to JSON format.

using System;
using System.Web.Script.Serialization;

public class Group
    // The JavaScriptSerializer ignores this field.
    public string Comment;

    // The JavaScriptSerializer serializes this field. 
    public string GroupName;


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

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5