JSONPathType
public protocol JSONPathType
A protocol used to define a path within an instance of JSON
that leads to some desired value.
A custom type, such as a RawRepresentable
enum, may be made to conform to JSONPathType
and used with the subscript APIs.
-
value(in:)
Default implementationUse
self
to key into adictionary
.Unlike Swift dictionaries, failing to find a value for a key should throw an error rather than convert to
nil
.Upon failure, implementers should throw an error from
JSON.Error
.Default Implementation
The default behavior for keying into a dictionary is to throw
JSON.Error.UnexpectedSubscript
.The default behavior for indexing into an array is to throw
JSON.Error.UnexpectedSubscript
. -
Use
self
to index into anarray
.Unlike Swift arrays, attempting to index outside the collection’s bounds should throw an error rather than crash.
Upon failure, implementers should throw an error from
JSON.Error
.