diff --git a/Sources/JSONDecoding/JSON.Object (ext).swift b/Sources/JSONDecoding/JSON.Object (ext).swift index 70d39d3..5ae87d2 100644 --- a/Sources/JSONDecoding/JSON.Object (ext).swift +++ b/Sources/JSONDecoding/JSON.Object (ext).swift @@ -1,3 +1,12 @@ +extension JSON.Object { + @inlinable public subscript(key: JSON.Key) -> JSON.OptionalDecoder { + JSON.OptionalDecoder(key: key, value: fields.first { $0.key == key }?.value) + } + + @inlinable public subscript(key: JSON.Key) -> JSON.FieldDecoder? { + (fields.first { $0.key == key }?.value).map { JSON.FieldDecoder(key: key, value: $0) } + } +} extension JSON.Object: RandomAccessCollection { @inlinable public var startIndex: Int { self.fields.startIndex