docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class JsonSerialization

    High level API for serializing or deserializing json data from string, file or stream.

    Inheritance
    object
    JsonSerialization
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.Serialization.Json
    Assembly: Unity.Serialization.dll
    Syntax
    public static class JsonSerialization

    Methods

    AddGlobalAdapter(IJsonAdapter)

    Adds the specified IJsonAdapter to the set of global adapters. This is be included by default in all JsonSerialization calls.

    Declaration
    public static void AddGlobalAdapter(IJsonAdapter adapter)
    Parameters
    Type Name Description
    IJsonAdapter adapter

    The adapter to add.

    Exceptions
    Type Condition
    ArgumentException

    The given adapter is already registered.

    AddGlobalMigration(IJsonMigration)

    Adds the specified IJsonMigration to the set of global adapters. This is be included by default in all JsonSerialization calls.

    Declaration
    public static void AddGlobalMigration(IJsonMigration migration)
    Parameters
    Type Name Description
    IJsonMigration migration

    The migration to add.

    Exceptions
    Type Condition
    ArgumentException

    The given migration is already registered.

    FromJsonOverride<T>(FileInfo, ref T, JsonSerializationParameters)

    Deserializes from the specified path in to an existing instance of T.

    Declaration
    public static void FromJsonOverride<T>(FileInfo file, ref T container, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    FileInfo file

    The file to read from.

    T container

    The reference to be overwritten.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    FromJsonOverride<T>(Stream, ref T, JsonSerializationParameters)

    Deserializes from the specified stream in to an existing instance of T.

    Declaration
    public static void FromJsonOverride<T>(Stream stream, ref T container, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    Stream stream

    The stream to read from.

    T container

    The reference to be overwritten.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    FromJsonOverride<T>(string, ref T, JsonSerializationParameters)

    Deserializes from the specified json string in to an existing instance of T.

    Declaration
    public static void FromJsonOverride<T>(string json, ref T container, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    string json

    The json string to read from.

    T container

    The reference to be overwritten.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    FromJsonOverride<T>(SerializedValueView, ref T, JsonSerializationParameters)

    Deserializes from the specified SerializedValueView in to an existing instance of T.

    Declaration
    public static void FromJsonOverride<T>(SerializedValueView view, ref T container, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    SerializedValueView view

    The view to read from.

    T container

    The reference to be overwritten.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    FromJson<T>(FileInfo, JsonSerializationParameters)

    Deserializes from the specified path and returns a new instance of T.

    Declaration
    public static T FromJson<T>(FileInfo file, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    FileInfo file

    The file to read from.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    T

    A new instance of T constructed from the serialized data.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    FromJson<T>(Stream, JsonSerializationParameters)

    Deserializes from the specified stream and returns a new instance of T.

    Declaration
    public static T FromJson<T>(Stream stream, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    Stream stream

    The stream to read from.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    T

    A new instance of T constructed from the serialized data.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    FromJson<T>(string, JsonSerializationParameters)

    Deserializes from the specified json string and returns a new instance of T.

    Declaration
    public static T FromJson<T>(string json, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    string json

    The json string to read from.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    T

    A new instance of T constructed from the serialized data.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    FromJson<T>(SerializedValueView, JsonSerializationParameters)

    Deserializes from the specified SerializedValueView and returns a new instance of T.

    Declaration
    public static T FromJson<T>(SerializedValueView view, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    SerializedValueView view

    The view to read from.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    T

    A new instance of T constructed from the serialized data.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    RemoveGlobalAdapter(IJsonAdapter)

    Removes the specified IJsonAdapter from the set of global adapters.

    Declaration
    public static void RemoveGlobalAdapter(IJsonAdapter adapter)
    Parameters
    Type Name Description
    IJsonAdapter adapter

    The adapter to remove.

    Exceptions
    Type Condition
    ArgumentException

    The given adapter has not been registered.

    RemoveGlobalMigration(IJsonMigration)

    Removes the specified IJsonAdapter from the set of global adapters.

    Declaration
    public static void RemoveGlobalMigration(IJsonMigration migration)
    Parameters
    Type Name Description
    IJsonMigration migration

    The migration to remove.

    Exceptions
    Type Condition
    ArgumentException

    The given migration has not been registered.

    ToJson<T>(FileInfo, T, JsonSerializationParameters)

    Serializes the given object to a json file at the specified path.

    Declaration
    public static void ToJson<T>(FileInfo file, T container, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    FileInfo file

    The file to write to.

    T container

    The object to serialize.

    JsonSerializationParameters parameters

    The parameters to use when writing.

    Type Parameters
    Name Description
    T

    The type to serialize.

    ToJson<T>(JsonWriter, T, JsonSerializationParameters)

    Writes a property container the specified buffer.

    Declaration
    public static void ToJson<T>(JsonWriter writer, T value, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    JsonWriter writer

    The buffer to write the object to.

    T value

    The container to write.

    JsonSerializationParameters parameters

    The parameters to use when writing.

    Type Parameters
    Name Description
    T

    The type to serialize.

    ToJson<T>(T, JsonSerializationParameters)

    Writes a property container to a json string.

    Declaration
    public static string ToJson<T>(T value, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    T value

    The container to write.

    JsonSerializationParameters parameters

    The parameters to use when writing.

    Returns
    Type Description
    string

    A json string.

    Type Parameters
    Name Description
    T

    The type to serialize.

    TryFromJsonOverride<T>(FileInfo, ref T, out DeserializationResult, JsonSerializationParameters)

    Deserializes from the specified path in to an existing instance of T.

    Declaration
    public static bool TryFromJsonOverride<T>(FileInfo file, ref T container, out DeserializationResult result, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    FileInfo file

    The file to read from.

    T container

    The reference to be overwritten.

    DeserializationResult result

    The results structure containing any errors or exceptions.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    bool

    True if the deserialization succeeded; otherwise, false.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    TryFromJsonOverride<T>(Stream, ref T, out DeserializationResult, JsonSerializationParameters)

    Deserializes from the specified stream in to an existing instance of T.

    Declaration
    public static bool TryFromJsonOverride<T>(Stream stream, ref T container, out DeserializationResult result, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    Stream stream

    The stream to read from.

    T container

    The reference to be overwritten.

    DeserializationResult result

    The results structure containing any errors or exceptions.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    bool

    True if the deserialization succeeded; otherwise, false.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    TryFromJsonOverride<T>(string, ref T, out DeserializationResult, JsonSerializationParameters)

    Deserializes from the specified json string in to an existing instance of T.

    Declaration
    public static bool TryFromJsonOverride<T>(string json, ref T container, out DeserializationResult result, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    string json

    The json string to read from.

    T container

    The reference to be overwritten.

    DeserializationResult result

    The results structure containing any errors or exceptions.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    bool

    True if the deserialization succeeded; otherwise, false.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    TryFromJsonOverride<T>(SerializedValueView, ref T, out DeserializationResult, JsonSerializationParameters)

    Deserializes from the specified SerializedValueView in to an existing instance of T.

    Declaration
    public static bool TryFromJsonOverride<T>(SerializedValueView view, ref T container, out DeserializationResult result, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    SerializedValueView view

    The view to read from.

    T container

    The reference to be overwritten.

    DeserializationResult result

    The results structure containing any errors or exceptions.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    bool

    True if the deserialization succeeded; otherwise, false.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    TryFromJson<T>(FileInfo, out T, out DeserializationResult, JsonSerializationParameters)

    Deserializes from the specified path and returns a new instance of T.

    Declaration
    public static bool TryFromJson<T>(FileInfo file, out T container, out DeserializationResult result, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    FileInfo file

    The file to read from.

    T container

    When this method returns, contains the deserialized value.

    DeserializationResult result

    The results structure containing any errors or exceptions.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    bool

    True if the deserialization succeeded; otherwise, false.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    TryFromJson<T>(Stream, out T, out DeserializationResult, JsonSerializationParameters)

    Deserializes from the specified stream and returns a new instance of T.

    Declaration
    public static bool TryFromJson<T>(Stream stream, out T container, out DeserializationResult result, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    Stream stream

    The stream to read from.

    T container

    When this method returns, contains the deserialized value.

    DeserializationResult result

    The results structure containing any errors or exceptions.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    bool

    True if the deserialization succeeded; otherwise, false.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    TryFromJson<T>(string, out T, out DeserializationResult, JsonSerializationParameters)

    Deserializes from the specified json string and returns a new instance of T.

    Declaration
    public static bool TryFromJson<T>(string json, out T container, out DeserializationResult result, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    string json

    The json string to read from.

    T container

    When this method returns, contains the deserialized value.

    DeserializationResult result

    The results structure containing any errors or exceptions.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    bool

    True if the deserialization succeeded; otherwise, false.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    TryFromJson<T>(SerializedValueView, ref T, out DeserializationResult, JsonSerializationParameters)

    Deserializes from the specified SerializedValueView and returns a new instance of T.

    Declaration
    public static bool TryFromJson<T>(SerializedValueView view, ref T container, out DeserializationResult result, JsonSerializationParameters parameters = default)
    Parameters
    Type Name Description
    SerializedValueView view

    The view to read from.

    T container

    When this method returns, contains the deserialized value.

    DeserializationResult result

    The results structure containing any errors or exceptions.

    JsonSerializationParameters parameters

    The reader parameters to use.

    Returns
    Type Description
    bool

    True if the deserialization succeeded; otherwise, false.

    Type Parameters
    Name Description
    T

    The type to deserialize.

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)