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 implementation

    Use self to key into a dictionary.

    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.

    Declaration

    Swift

    func value(in dictionary: [String : JSON]) throws -> JSON
  • Use self to index into an array.

    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.

    Declaration

    Swift

    func value(in array: [JSON]) throws -> JSON