JSON
public enum JSON
An enum to describe the structure of JSON.
-
A case for denoting an array with an associated value of
[JSON]
Declaration
Swift
case array([JSON])
-
A case for denoting a dictionary with an associated value of
[Swift.String: JSON]
Declaration
Swift
case dictionary([String: JSON])
-
A case for denoting a double with an associated value of
Swift.Double
.Declaration
Swift
case double(Double)
-
A case for denoting an integer with an associated value of
Swift.Int
.Declaration
Swift
case int(Int)
-
A case for denoting a string with an associated value of
Swift.String
.Declaration
Swift
case string(String)
-
A case for denoting a boolean with an associated value of
Swift.Bool
.Declaration
Swift
case bool(Bool)
-
A case for denoting null.
Declaration
Swift
case null
-
Attempt to serialize
JSON
into anData
. - returns: A byte-stream containing theJSON
ready for wire transfer. - throws: Errors that arise fromJSONSerialization
. - see: Foundation.JSONSerializationDeclaration
Swift
public func serialize() throws -> Data
Return Value
A byte-stream containing the
JSON
ready for wire transfer. -
Attempt to serialize
JSON
into aString
. - returns: AString
containing theJSON
. - throws: AJSON.Error.StringSerializationError
or errors that arise fromJSONSerialization
. - see: Foundation.JSONSerializationDeclaration
Swift
public func serializeString() throws -> String
Return Value
A
String
containing theJSON
.
-
A textual representation of
self
.Declaration
Swift
public var description: Swift.String
-
Attempts to decode into the returning type from a path into JSON. - parameter path: 0 or more
String
orInt
that subscript theJSON
. - parameter type: If the context this method is called from does not make the return type clear, pass a type implementingJSONDecodable
to disambiguate the type to decode with. - returns: An initialized member from the inner JSON. - throws: One of the following errors contained inJSON.Error
: *KeyNotFound
: A givenString
key does not exist inside a descendantJSON
dictionary. *IndexOutOfBounds
: A givenInt
index is outside the bounds of a descendantJSON
array. *UnexpectedSubscript
: A given subscript cannot be used with the correspondingJSON
value. *TypeNotConvertible
: The target value’s type inside of theJSON
instance does not matchDecoded
.Declaration
Swift
public func decode<Decoded: JSONDecodable>(at path: JSONPathType..., type: Decoded.Type = Decoded.self) throws -> Decoded
Parameters
path
0 or more
String
orInt
that subscript theJSON
.type
If the context this method is called from does not make the return type clear, pass a type implementing
JSONDecodable
to disambiguate the type to decode with.Return Value
An initialized member from the inner JSON.
-
Retrieves a
Double
from a path into JSON. - parameter path: 0 or moreString
orInt
that subscript theJSON
- returns: A floating-pointDouble
- throws: One of theJSON.Error
cases thrown bydecode(at:type:)
. - seealso:JSON.decode(at:type:)
Declaration
Swift
public func getDouble(at path: JSONPathType...) throws -> Double
Parameters
path
0 or more
String
orInt
that subscript theJSON
Return Value
A floating-point
Double
-
Retrieves an
Int
from a path into JSON. - parameter path: 0 or moreString
orInt
that subscript theJSON
- returns: A numericInt
- throws: One of theJSON.Error
cases thrown bydecode(at:type:)
. - seealso:JSON.decode(at:type:)
Declaration
Swift
public func getInt(at path: JSONPathType...) throws -> Int
Parameters
path
0 or more
String
orInt
that subscript theJSON
Return Value
A numeric
Int
-
Retrieves a
String
from a path into JSON. - parameter path: 0 or moreString
orInt
that subscript theJSON
- returns: A textualString
- throws: One of theJSON.Error
cases thrown bydecode(at:type:)
. - seealso:JSON.decode(at:type:)
Declaration
Swift
public func getString(at path: JSONPathType...) throws -> String
Parameters
path
0 or more
String
orInt
that subscript theJSON
Return Value
A textual
String
-
Retrieves a
Bool
from a path into JSON. - parameter path: 0 or moreString
orInt
that subscript theJSON
- returns: A truthyBool
- throws: One of theJSON.Error
cases thrown bydecode(at:type:)
. - seealso:JSON.decode(at:type:)
Declaration
Swift
public func getBool(at path: JSONPathType...) throws -> Bool
Parameters
path
0 or more
String
orInt
that subscript theJSON
Return Value
A truthy
Bool
-
Retrieves a
[JSON]
from a path into JSON. - parameter path: 0 or moreString
orInt
that subscript theJSON
- returns: AnArray
ofJSON
elements - throws: One of theJSON.Error
cases thrown bydecode(at:type:)
. - seealso:JSON.decode(at:type:)
Declaration
Swift
public func getArray(at path: JSONPathType...) throws -> [JSON]
Parameters
path
0 or more
String
orInt
that subscript theJSON
Return Value
An
Array
ofJSON
elements -
Attempts to decode many values from a descendant JSON array at a path into JSON. - parameter path: 0 or more
String
orInt
that subscript theJSON
- parameter type: If the context this method is called from does not make the return type clear, pass a type implementingJSONDecodable
to disambiguate the type to decode with. - returns: AnArray
of decoded elements - throws: One of theJSON.Error
cases thrown bydecode(at:type:)
, or any error that arises from decoding the contained values. - seealso:JSON.decode(at:type:)
Declaration
Swift
public func decodedArray<Decoded: JSONDecodable>(at path: JSONPathType..., type: Decoded.Type = Decoded.self) throws -> [Decoded]
Parameters
path
0 or more
String
orInt
that subscript theJSON
type
If the context this method is called from does not make the return type clear, pass a type implementing
JSONDecodable
to disambiguate the type to decode with.Return Value
An
Array
of decoded elements -
Retrieves a
[String: JSON]
from a path into JSON. - parameter path: 0 or moreString
orInt
that subscript theJSON
- returns: AnDictionary
ofString
mapping toJSON
elements - throws: One of theJSON.Error
cases thrown bydecode(at:type:)
. - seealso:JSON.decode(at:type:)
Declaration
Swift
public func getDictionary(at path: JSONPathType...) throws -> [String: JSON]
Parameters
path
0 or more
String
orInt
that subscript theJSON
Return Value
An
Dictionary
ofString
mapping toJSON
elements -
Attempts to decode many values from a descendant JSON object at a path into JSON. - parameter path: 0 or more
String
orInt
that subscript theJSON
- parameter type: If the context this method is called from does not make the return type clear, pass a type implementingJSONDecodable
to disambiguate the value type to decode with. - returns: ADictionary
ofString
keys and decoded values. - throws: One of theJSON.Error
cases thrown bydecode(at:type:)
or any error that arises from decoding the contained values. - seealso:JSON.decode(at:type:)
Declaration
Swift
public func decodedDictionary<Decoded: JSONDecodable>(at path: JSONPathType..., type: Decoded.Type = Decoded.self) throws -> [String: Decoded]
Parameters
path
0 or more
String
orInt
that subscript theJSON
type
If the context this method is called from does not make the return type clear, pass a type implementing
JSONDecodable
to disambiguate the value type to decode with.Return Value
A
Dictionary
ofString
keys and decoded values.
-
Optionally decodes into the returning type from a path into JSON. - parameter path: 0 or more
String
orInt
that subscript theJSON
- parameter alongPath: Options that control what should be done with values that arenull
or keys that are missing. - parameter type: If the context this method is called from does not make the return type clear, pass a type implementingJSONDecodable
to disambiguate the type to decode with. - returns: A decoded value from the inner JSON if found, ornil
. - throws: One of the following errors contained inJSON.Error
: *KeyNotFound
: A keypath
does not exist inside a descendantJSON
dictionary. *IndexOutOfBounds
: An indexpath
is outside the bounds of a descendantJSON
array. *UnexpectedSubscript
: Apath
item cannot be used with the correspondingJSON
value. *TypeNotConvertible
: The target value’s type inside of theJSON
instance does not match the decoded value. * Any error that arises from decoding the value.Declaration
Swift
public func decode<Decoded: JSONDecodable>(at path: JSONPathType..., alongPath options: SubscriptingOptions, type: Decoded.Type = Decoded.self) throws -> Decoded?
Parameters
path
0 or more
String
orInt
that subscript theJSON
alongPath
Options that control what should be done with values that are
null
or keys that are missing.type
If the context this method is called from does not make the return type clear, pass a type implementing
JSONDecodable
to disambiguate the type to decode with.Return Value
A decoded value from the inner JSON if found, or
nil
. -
Optionally retrieves a
Double
from a path into JSON. - parameter path: 0 or moreString
orInt
that subscript theJSON
. - parameter alongPath: Options that control what should be done with values that arenull
or keys that are missing. - returns: ADouble
if a value could be found, otherwisenil
. - throws: One of the following errors contained inJSON.Error
: *KeyNotFound
: A keypath
does not exist inside a descendantJSON
dictionary. *IndexOutOfBounds
: An indexpath
is outside the bounds of a descendantJSON
array. *UnexpectedSubscript
: Apath
item cannot be used with the correspondingJSON
value. *TypeNotConvertible
: The target value’s type inside of theJSON
instance does not match the decoded value.Declaration
Swift
public func getDouble(at path: JSONPathType..., alongPath options: SubscriptingOptions) throws -> Double?
Parameters
path
0 or more
String
orInt
that subscript theJSON
.alongPath
Options that control what should be done with values that are
null
or keys that are missing.Return Value
A
Double
if a value could be found, otherwisenil
. -
Optionally retrieves a
Int
from a path into JSON. - parameter path: 0 or moreString
orInt
that subscript theJSON
- parameter alongPath: Options that control what should be done with values that arenull
or keys that are missing. - returns: A numericInt
if a value could be found, otherwisenil
. - throws: One of the following errors contained inJSON.Error
: *KeyNotFound
: A keypath
does not exist inside a descendantJSON
dictionary. *IndexOutOfBounds
: An indexpath
is outside the bounds of a descendantJSON
array. *UnexpectedSubscript
: Apath
item cannot be used with the correspondingJSON
value. *TypeNotConvertible
: The target value’s type inside of theJSON
instance does not match the decoded value.Declaration
Swift
public func getInt(at path: JSONPathType..., alongPath options: SubscriptingOptions) throws -> Int?
Parameters
path
0 or more
String
orInt
that subscript theJSON
alongPath
Options that control what should be done with values that are
null
or keys that are missing.Return Value
A numeric
Int
if a value could be found, otherwisenil
. -
Optionally retrieves a
String
from a path into JSON. - parameter path: 0 or moreString
orInt
that subscript theJSON
- parameter alongPath: Options that control what should be done with values that arenull
or keys that are missing. - returns: A textString
if a value could be found, otherwisenil
. - throws: One of the following errors contained inJSON.Error
: *KeyNotFound
: A keypath
does not exist inside a descendantJSON
dictionary. *IndexOutOfBounds
: An indexpath
is outside the bounds of a descendantJSON
array. *UnexpectedSubscript
: Apath
item cannot be used with the correspondingJSON
value. *TypeNotConvertible
: The target value’s type inside of theJSON
instance does not match the decoded value.Declaration
Swift
public func getString(at path: JSONPathType..., alongPath options: SubscriptingOptions) throws -> String?
Parameters
path
0 or more
String
orInt
that subscript theJSON
alongPath
Options that control what should be done with values that are
null
or keys that are missing.Return Value
A text
String
if a value could be found, otherwisenil
. -
Optionally retrieves a
Bool
from a path into JSON. - parameter path: 0 or moreString
orInt
that subscript theJSON
- parameter alongPath: Options that control what should be done with values that arenull
or keys that are missing. - returns: A truthyBool
if a value could be found, otherwisenil
. - throws: One of the following errors contained inJSON.Error
: *KeyNotFound
: A keypath
does not exist inside a descendantJSON
dictionary. *IndexOutOfBounds
: An indexpath
is outside the bounds of a descendantJSON
array. *UnexpectedSubscript
: Apath
item cannot be used with the correspondingJSON
value. *TypeNotConvertible
: The target value’s type inside of theJSON
instance does not match the decoded value.Declaration
Swift
public func getBool(at path: JSONPathType..., alongPath options: SubscriptingOptions) throws -> Bool?
Parameters
path
0 or more
String
orInt
that subscript theJSON
alongPath
Options that control what should be done with values that are
null
or keys that are missing.Return Value
A truthy
Bool
if a value could be found, otherwisenil
. -
Optionally retrieves a
[JSON]
from a path into the recieving structure. - parameter path: 0 or moreString
orInt
that subscript theJSON
- parameter alongPath: Options that control what should be done with values that arenull
or keys that are missing. - returns: AnArray
ofJSON
elements if a value could be found, otherwisenil
. - throws: One of the following errors contained inJSON.Error
: *KeyNotFound
: A keypath
does not exist inside a descendantJSON
dictionary. *IndexOutOfBounds
: An indexpath
is outside the bounds of a descendantJSON
array. *UnexpectedSubscript
: Apath
item cannot be used with the correspondingJSON
value. *TypeNotConvertible
: The target value’s type inside of theJSON
instance does not match the decoded value.Declaration
Swift
public func getArray(at path: JSONPathType..., alongPath options: SubscriptingOptions) throws -> [JSON]?
Parameters
path
0 or more
String
orInt
that subscript theJSON
alongPath
Options that control what should be done with values that are
null
or keys that are missing.Return Value
An
Array
ofJSON
elements if a value could be found, otherwisenil
. -
Optionally decodes many values from a descendant array at a path into JSON. - parameter path: 0 or more
String
orInt
that subscript theJSON
- parameter alongPath: Options that control what should be done with values that arenull
or keys that are missing. - parameter type: If the context this method is called from does not make the return type clear, pass a type implementingJSONDecodable
to disambiguate the value type to decode with. - returns: AnArray
of decoded elements if found, otherwisenil
. - throws: One of the following errors contained inJSON.Error
: *KeyNotFound
: A keypath
does not exist inside a descendantJSON
dictionary. *IndexOutOfBounds
: An indexpath
is outside the bounds of a descendantJSON
array. *UnexpectedSubscript
: Apath
item cannot be used with the correspondingJSON
value. *TypeNotConvertible
: The target value’s type inside of theJSON
instance does not match the decoded value. * Any error that arises from decoding the value.Declaration
Swift
public func decodedArray<Decoded: JSONDecodable>(at path: JSONPathType..., alongPath options: SubscriptingOptions, type: Decoded.Type = Decoded.self) throws -> [Decoded]?
Parameters
path
0 or more
String
orInt
that subscript theJSON
alongPath
Options that control what should be done with values that are
null
or keys that are missing.type
If the context this method is called from does not make the return type clear, pass a type implementing
JSONDecodable
to disambiguate the value type to decode with.Return Value
An
Array
of decoded elements if found, otherwisenil
. -
Optionally retrieves a
[String: JSON]
from a path into the recieving structure. - parameter path: 0 or moreString
orInt
that subscript theJSON
- parameter alongPath: Options that control what should be done with values that arenull
or keys that are missing. - returns: ADictionary
ofString
mapping toJSON
elements if a value could be found, otherwisenil
. - throws: One of the following errors contained inJSON.Error
: *KeyNotFound
: A keypath
does not exist inside a descendantJSON
dictionary. *IndexOutOfBounds
: An indexpath
is outside the bounds of a descendantJSON
array. *UnexpectedSubscript
: Apath
item cannot be used with the correspondingJSON
value. *TypeNotConvertible
: The target value’s type inside of theJSON
instance does not match the decoded value.Declaration
Swift
public func getDictionary(at path: JSONPathType..., alongPath options: SubscriptingOptions) throws -> [String: JSON]?
Parameters
path
0 or more
String
orInt
that subscript theJSON
alongPath
Options that control what should be done with values that are
null
or keys that are missing.Return Value
A
Dictionary
ofString
mapping toJSON
elements if a value could be found, otherwisenil
. -
Optionally attempts to decode many values from a descendant object at a path into JSON. - parameter path: 0 or more
String
orInt
that subscript theJSON
- parameter alongPath: Options that control what should be done with values that arenull
or keys that are missing. - parameter type: If the context this method is called from does not make the return type clear, pass a type implementingJSONDecodable
to disambiguate the value type to decode with. - returns: ADictionary
ofString
mapping to decoded elements if a value could be found, otherwisenil
. - throws: One of the following errors contained inJSON.Error
: *KeyNotFound
: A keypath
does not exist inside a descendantJSON
dictionary. *IndexOutOfBounds
: An indexpath
is outside the bounds of a descendantJSON
array. *UnexpectedSubscript
: Apath
item cannot be used with the correspondingJSON
value. *TypeNotConvertible
: The target value’s type inside of theJSON
instance does not match the decoded value. * Any error that arises from decoding the value.Declaration
Swift
public func decodedDictionary<Decoded: JSONDecodable>(at path: JSONPathType..., alongPath options: SubscriptingOptions, type: Decoded.Type = Decoded.self) throws -> [String: Decoded]?
Parameters
path
0 or more
String
orInt
that subscript theJSON
alongPath
Options that control what should be done with values that are
null
or keys that are missing.type
If the context this method is called from does not make the return type clear, pass a type implementing
JSONDecodable
to disambiguate the value type to decode with.Return Value
A
Dictionary
ofString
mapping to decoded elements if a value could be found, otherwisenil
.
-
Attempts to decode into the returning type from a path into JSON, or returns a fallback if not found. - parameter path: 0 or more
String
orInt
that subscript theJSON
- parameter fallback: Value to use when one is missing at the subscript. - returns: An initialized member from the inner JSON. - throws: One of the following errors contained inJSON.Error
: *UnexpectedSubscript
: A given subscript cannot be used with the correspondingJSON
value. *TypeNotConvertible
: The target value’s type inside of theJSON
instance does not matchDecoded
.Declaration
Swift
public func decode<Decoded: JSONDecodable>(at path: JSONPathType..., or fallback: @autoclosure() -> Decoded) throws -> Decoded
Parameters
path
0 or more
String
orInt
that subscript theJSON
fallback
Value to use when one is missing at the subscript.
Return Value
An initialized member from the inner JSON.
-
Retrieves a
Double
from a path into JSON or a fallback if not found. - parameter path: 0 or moreString
orInt
that subscript theJSON
- parameter fallback:Double
to use when one is missing at the subscript. - returns: A floating-pointDouble
- throws: One of theJSON.Error
cases thrown by callingmapOptional(at:fallback:transform:)
.Declaration
Swift
public func getDouble(at path: JSONPathType..., or fallback: @autoclosure() -> Double) throws -> Double
Parameters
path
0 or more
String
orInt
that subscript theJSON
fallback
Double
to use when one is missing at the subscript.Return Value
A floating-point
Double
-
Retrieves an
Int
from a path into JSON or a fallback if not found. - parameter path: 0 or moreString
orInt
that subscript theJSON
- parameter fallback:Int
to use when one is missing at the subscript. - returns: A numericInt
- throws: One of the following errors contained inJSON.Error
: *KeyNotFound
: A keypath
does not exist inside a descendantJSON
dictionary. *IndexOutOfBounds
: An indexpath
is outside the bounds of a descendantJSON
array. *UnexpectedSubscript
: Apath
item cannot be used with the correspondingJSON
value. *TypeNotConvertible
: The target value’s type inside of theJSON
instance does not match the decoded value.Declaration
Swift
public func getInt(at path: JSONPathType..., or fallback: @autoclosure() -> Int) throws -> Int
Parameters
path
0 or more
String
orInt
that subscript theJSON
fallback
Int
to use when one is missing at the subscript.Return Value
A numeric
Int
-
Retrieves a
String
from a path into JSON or a fallback if not found. - parameter path: 0 or moreString
orInt
that subscript theJSON
- parameter fallback:String
to use when one is missing at the subscript. - returns: A textualString
- throws: One of the following errors contained inJSON.Error
: *KeyNotFound
: A keypath
does not exist inside a descendantJSON
dictionary. *IndexOutOfBounds
: An indexpath
is outside the bounds of a descendantJSON
array. *UnexpectedSubscript
: Apath
item cannot be used with the correspondingJSON
value. *TypeNotConvertible
: The target value’s type inside of theJSON
instance does not match the decoded value.Declaration
Swift
public func getString(at path: JSONPathType..., or fallback: @autoclosure() -> String) throws -> String
Parameters
path
0 or more
String
orInt
that subscript theJSON
fallback
String
to use when one is missing at the subscript.Return Value
A textual
String
-
Retrieves a
Bool
from a path into JSON or a fallback if not found. - parameter path: 0 or moreString
orInt
that subscript theJSON
- parameter fallback:Bool
to use when one is missing at the subscript. - returns: A truthyBool
- throws: One of the following errors contained inJSON.Error
: *KeyNotFound
: A keypath
does not exist inside a descendantJSON
dictionary. *IndexOutOfBounds
: An indexpath
is outside the bounds of a descendantJSON
array. *UnexpectedSubscript
: Apath
item cannot be used with the correspondingJSON
value. *TypeNotConvertible
: The target value’s type inside of theJSON
instance does not match the decoded value.Declaration
Swift
public func getBool(at path: JSONPathType..., or fallback: @autoclosure() -> Bool) throws -> Bool
Parameters
path
0 or more
String
orInt
that subscript theJSON
fallback
Bool
to use when one is missing at the subscript.Return Value
A truthy
Bool
-
Retrieves a
[JSON]
from a path into JSON or a fallback if not found. - parameter path: 0 or moreString
orInt
that subscript theJSON
- parameter fallback:Array
to use when one is missing at the subscript. - returns: AnArray
ofJSON
elements - throws: One of the following errors contained inJSON.Error
: *KeyNotFound
: A keypath
does not exist inside a descendantJSON
dictionary. *IndexOutOfBounds
: An indexpath
is outside the bounds of a descendantJSON
array. *UnexpectedSubscript
: Apath
item cannot be used with the correspondingJSON
value. *TypeNotConvertible
: The target value’s type inside of theJSON
instance does not match the decoded value.Declaration
Swift
public func getArray(at path: JSONPathType..., or fallback: @autoclosure() -> [JSON]) throws -> [JSON]
Parameters
path
0 or more
String
orInt
that subscript theJSON
fallback
Array
to use when one is missing at the subscript.Return Value
An
Array
ofJSON
elements -
Attempts to decodes many values from a desendant JSON array at a path into the recieving structure, returning a fallback if not found. - parameter path: 0 or more
String
orInt
that subscript theJSON
- parameter fallback:Array
to use when one is missing at the subscript. - returns: AnArray
of decoded elements - throws: One of the following errors contained inJSON.Error
: *KeyNotFound
: A keypath
does not exist inside a descendantJSON
dictionary. *IndexOutOfBounds
: An indexpath
is outside the bounds of a descendantJSON
array. *UnexpectedSubscript
: Apath
item cannot be used with the correspondingJSON
value. *TypeNotConvertible
: The target value’s type inside of theJSON
instance does not match the decoded value. * Any error that arises from decoding the value.Declaration
Swift
public func decodedArray<Decoded: JSONDecodable>(at path: JSONPathType..., or fallback: @autoclosure() -> [Decoded]) throws -> [Decoded]
Parameters
path
0 or more
String
orInt
that subscript theJSON
fallback
Array
to use when one is missing at the subscript.Return Value
An
Array
of decoded elements -
Retrieves a
[String: JSON]
from a path into JSON or a fallback if not found. - parameter path: 0 or moreString
orInt
that subscript theJSON
- parameter fallback:Dictionary
to use when one is missing at the subscript. - returns: AnDictionary
ofString
mapping toJSON
elements - throws: One of the following errors contained inJSON.Error
: *KeyNotFound
: A keypath
does not exist inside a descendantJSON
dictionary. *IndexOutOfBounds
: An indexpath
is outside the bounds of a descendantJSON
array. *UnexpectedSubscript
: Apath
item cannot be used with the correspondingJSON
value. *TypeNotConvertible
: The target value’s type inside of theJSON
instance does not match the decoded value.Declaration
Swift
public func getDictionary(at path: JSONPathType..., or fallback: @autoclosure() -> [String: JSON]) throws -> [String: JSON]
Parameters
path
0 or more
String
orInt
that subscript theJSON
fallback
Dictionary
to use when one is missing at the subscript.Return Value
An
Dictionary
ofString
mapping toJSON
elements -
Attempts to decode many values from a descendant JSON object at a path into the receiving structure, returning a fallback if not found. - parameter path: 0 or more
String
orInt
that subscript theJSON
- parameter fallback: Value to use when one is missing at the subscript - returns: ADictionary
ofString
mapping to decoded elements. - throws: One of the following errors contained inJSON.Error
: *KeyNotFound
: A keypath
does not exist inside a descendantJSON
dictionary. *IndexOutOfBounds
: An indexpath
is outside the bounds of a descendantJSON
array. *UnexpectedSubscript
: Apath
item cannot be used with the correspondingJSON
value. *TypeNotConvertible
: The target value’s type inside of theJSON
instance does not match the decoded value. * Any error that arises from decoding the value.Declaration
Swift
public func decodedDictionary<Decoded: JSONDecodable>(at path: JSONPathType..., or fallback: @autoclosure() -> [String: Decoded]) throws -> [String: Decoded]
Parameters
path
0 or more
String
orInt
that subscript theJSON
fallback
Value to use when one is missing at the subscript
Return Value
A
Dictionary
ofString
mapping to decoded elements.
-
Create
JSON
from UTF-8data
. By default, parses using the Swift-nativeJSONParser
backend.Declaration
Swift
public init(data: Data, usingParser parser: JSONParserType.Type = JSONParser.self) throws
-
Create
JSON
from UTF-8string
.Declaration
Swift
public init(jsonString: Swift.String, usingParser parser: JSONParserType.Type = JSONParser.self) throws
-
Create an instance by copying each element of the
collection
into a newArray
.Declaration
Swift
public init<Collection: Swift.Collection>(_ collection: Collection) where Collection.Iterator.Element == JSON
-
Create an instance initialized with
elements
.Declaration
Swift
public init(arrayLiteral elements: JSON...)
-
Create an instance by copying each key/value pair of the
pairs
into a newDictionary
.Declaration
Swift
public init<Dictionary: Sequence>(_ pairs: Dictionary) where Dictionary.Iterator.Element == (Swift.String, JSON)
-
Create an instance initialized with
pairs
.Declaration
Swift
public init(dictionaryLiteral pairs: (Swift.String, JSON)...)
-
Create an instance initialized to
dictionary
.Declaration
Swift
public init(_ dictionary: Swift.Dictionary<Swift.String, JSON>)
-
Create an instance initialized to
Double
value
.Declaration
Swift
public init(_ value: Swift.Double)
-
Create a literal instance initialized to
value
.Declaration
Swift
public init(floatLiteral value: Swift.Double)
-
Create an instance initialized to
Int
byvalue
.Declaration
Swift
public init(_ value: Swift.Int)
-
Create a literal instance initialized to
value
.Declaration
Swift
public init(integerLiteral value: Swift.Int)
-
Create an instance initialized to
String
bytext
.Declaration
Swift
public init(_ text: Swift.String)
-
Create a literal instance initialized to
value
.Declaration
Swift
public init(stringLiteral value: StringLiteralType)
-
Create a literal instance initialized to
value
.Declaration
Swift
public init(extendedGraphemeClusterLiteral value: StringLiteralType)
-
Create a literal instance initialized to
value
.Declaration
Swift
public init(unicodeScalarLiteral value: StringLiteralType)
-
Create an instance initialized to
Bool
byvalue
.Declaration
Swift
public init(_ value: Swift.Bool)
-
Create a literal instance initialized to
value
.Declaration
Swift
public init(booleanLiteral value: Swift.Bool)
-
Create an instance initialized with
nil
.Declaration
Swift
public init(nilLiteral: ())
-
Retrieves a
[JSON]
from the JSON. - parameter: AJSON
to be used to create the returnedArray
. - returns: AnArray
ofJSON
elements - throws: Any of theJSON.Error
cases thrown bydecode(type:)
. - seealso:JSON.decode(_:type:)
Declaration
Swift
static func getArray(from json: JSON) throws -> [JSON]
Return Value
An
Array
ofJSON
elements -
Retrieves a
[String: JSON]
from the JSON. - parameter: AJSON
to be used to create the returnedDictionary
. - returns: AnDictionary
ofString
mapping toJSON
elements - throws: Any of theJSON.Error
cases thrown bydecode(type:)
. - seealso:JSON.decode(_:type:)
Declaration
Swift
static func getDictionary(from json: JSON) throws -> [String: JSON]
Return Value
An
Dictionary
ofString
mapping toJSON
elements -
Attempts to decode many values from a descendant JSON array at a path into JSON. - parameter json: A
JSON
to be used to create the returnedArray
of some type conforming toJSONDecodable
. - returns: AnArray
ofDecoded
elements. - throws: Any of theJSON.Error
cases thrown bydecode(type:)
, as well as any error that arises from decoding the contained values. - seealso:JSON.decode(_:type:)
Declaration
Swift
static func decodedArray<Decoded: JSONDecodable>(from json: JSON) throws -> [Decoded]
Parameters
json
A
JSON
to be used to create the returnedArray
of some type conforming toJSONDecodable
.Return Value
An
Array
ofDecoded
elements. -
Attempts to decode many values from a descendant JSON object at a path into JSON. - parameter json: A
JSON
to be used to create the returnedDictionary
of some type conforming toJSONDecodable
. - returns: ADictionary
of string keys andDecoded
values. - throws: One of theJSON.Error
cases thrown bydecode(_:type:)
or any error that arises from decoding the contained values. - seealso:JSON.decode(_:type:)
Declaration
Swift
static func decodedDictionary<Decoded: JSONDecodable>(from json: JSON) throws -> [Swift.String: Decoded]
Parameters
json
A
JSON
to be used to create the returnedDictionary
of some type conforming toJSONDecodable
.Return Value
A
Dictionary
of string keys andDecoded
values.