JSONCoder

public final class JSONCoder

Converts between JSON and other Codable types.

  • Converts an Encodable type to a JSON instance

    Throws

    Encoding errors that occur when encoding the Encoodable type to JSON.

    Declaration

    Swift

    public static func encode<T>(_ t: T) throws -> JSON where T : Encodable

    Parameters

    t

    The Encodable value to convert.

    Return Value

    The JSON that represents the Encodable value.

  • Converts a JSON instance to a Decoable type.

    Throws

    Decoding errors that occur when decoding JSON to T.

    Declaration

    Swift

    public static func decode<T>(_ type: T.Type, from json: JSON) throws -> T where T : Decodable

    Parameters

    type

    The Decodable type to create from the JSON.

    json

    The JSON instance to convert to type T.

    Return Value

    An instance of T created from the JSON instance passed in.