JSON-Combinator 0.2.3 → 0.2.4
raw patch · 4 files changed
+24/−16 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Text.JSON.Failure: NoSuchFieldOrExpectedObject :: (forall x. (NoSuchField z -> x) -> (ExpectedObject j -> x) -> x) -> NoSuchFieldOrExpectedObject z j
+ Text.JSON.Failure: data NoSuchFieldOrExpectedObject z j
- Text.JSON.Combinator: (-|) :: (JSONField j f, Failure (NoSuchField f) m) => f -> j -> m j
+ Text.JSON.Combinator: (-|) :: (JSONField j f, Failure (NoSuchFieldOrExpectedObject f j) m) => f -> j -> m j
- Text.JSON.Combinator: (-||) :: (Foldable t, Failure (NoSuchField f) m, JSONField j f) => t f -> j -> m j
+ Text.JSON.Combinator: (-||) :: (Foldable t, Failure (NoSuchFieldOrExpectedObject f j) m, JSONField j f) => t f -> j -> m j
- Text.JSON.Combinator: field' :: (Foldable t, Failure (NoSuchField f) m, JSONField j f) => t f -> j -> m j
+ Text.JSON.Combinator: field' :: (Foldable t, Failure (NoSuchFieldOrExpectedObject f j) m, JSONField j f) => t f -> j -> m j
- Text.JSON.JSONField: field :: (JSONField j f, Failure (NoSuchField f) m) => f -> j -> m j
+ Text.JSON.JSONField: field :: (JSONField j f, Failure (NoSuchFieldOrExpectedObject f j) m) => f -> j -> m j
Files
- JSON-Combinator.cabal +1/−1
- Text/JSON/Combinator.hs +3/−3
- Text/JSON/Failure.hs +6/−1
- Text/JSON/JSONField.hs +14/−11
JSON-Combinator.cabal view
@@ -1,5 +1,5 @@ Name: JSON-Combinator-Version: 0.2.3+Version: 0.2.4 License: BSD3 License-File: LICENSE Author: Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ>
Text/JSON/Combinator.hs view
@@ -428,7 +428,7 @@ -- | Returns the possible value associated with the given field if this is an object. An alias for 'field'. (-|) ::- (JSONField j f, Failure (NoSuchField f) m) =>+ (JSONField j f, Failure (NoSuchFieldOrExpectedObject f j) m) => f -> j -- ^ The JSON value. -> m j@@ -576,7 +576,7 @@ -- | Traverses down JSON objects with the association fields and returns the potential value. field' ::- (F.Foldable t, Failure (NoSuchField f) m, JSONField j f) =>+ (F.Foldable t, Failure (NoSuchFieldOrExpectedObject f j) m, JSONField j f) => t f -> j -> m j@@ -585,7 +585,7 @@ -- | Traverses down JSON objects with the association fields and returns the potential value. An alias for 'field''. (-||) ::- (F.Foldable t, Failure (NoSuchField f) m, JSONField j f) =>+ (F.Foldable t, Failure (NoSuchFieldOrExpectedObject f j) m, JSONField j f) => t f -> j -> m j
Text/JSON/Failure.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE RankNTypes, DeriveDataTypeable #-} -- | Data structures that used to denote failure of accessing JSON values. module Text.JSON.Failure@@ -9,6 +9,7 @@ , ExpectedNumber(..) , ExpectedString(..) , ExpectedArray(..)+, NoSuchFieldOrExpectedObject(..) ) where import Data.Data@@ -42,3 +43,7 @@ data ExpectedString j = ExpectedString j deriving (Eq, Ord, Show, Data, Typeable)++data NoSuchFieldOrExpectedObject z j =+ NoSuchFieldOrExpectedObject (forall x. (NoSuchField z -> x) -> (ExpectedObject j -> x) -> x)+
Text/JSON/JSONField.hs view
@@ -16,17 +16,20 @@ import Control.Failure import qualified Data.Map as M +-- | Accessing JSON object fields. class JSONField j f | j -> f where+ -- | Access the field of a JSON object with potential failure. field ::- Failure (NoSuchField f) m =>+ Failure (NoSuchFieldOrExpectedObject f j) m => f -> j -> m j+ -- | Access all fields of a JSON object with potential failure. fields :: Failure (ExpectedObject j) m => j -> m [f]- -- | Returns the potential object field values of a JSON value.+ -- | Returns all object field values of a JSON value. values :: Failure (ExpectedObject j) m => j@@ -35,10 +38,10 @@ instance JSONField JSON ByteString where field f (Object o) = case T.lookup f o of- Nothing -> failure (NoSuchField f)+ Nothing -> failure (NoSuchFieldOrExpectedObject (\x _ -> x (NoSuchField f)) :: NoSuchFieldOrExpectedObject ByteString JSON) Just x -> return x- field f _ =- failure (NoSuchField f)+ field _ j =+ failure (NoSuchFieldOrExpectedObject (\_ y -> y (ExpectedObject j)) :: NoSuchFieldOrExpectedObject ByteString JSON) fields (Object o) = return (T.keys o) fields j =@@ -51,10 +54,10 @@ instance JSONField J.JSValue [Char] where field f (J.JSObject (JSONObject o)) = case lookup f o of- Nothing -> failure (NoSuchField f)+ Nothing -> failure (NoSuchFieldOrExpectedObject (\x _ -> x (NoSuchField f)) :: NoSuchFieldOrExpectedObject String J.JSValue) Just x -> return x- field f _ =- failure (NoSuchField f)+ field _ j =+ failure (NoSuchFieldOrExpectedObject (\_ y -> y (ExpectedObject j)) :: NoSuchFieldOrExpectedObject String J.JSValue) fields (J.JSObject (JSONObject o)) = return (fmap fst o) fields j =@@ -67,10 +70,10 @@ instance JSONField H.Json [Char] where field f (H.JObject o) = case M.lookup f o of- Nothing -> failure (NoSuchField f)+ Nothing -> failure (NoSuchFieldOrExpectedObject (\x _ -> x (NoSuchField f)) :: NoSuchFieldOrExpectedObject String H.Json) Just x -> return x- field f _ =- failure (NoSuchField f)+ field _ j =+ failure (NoSuchFieldOrExpectedObject (\_ y -> y (ExpectedObject j)) :: NoSuchFieldOrExpectedObject String H.Json) fields (H.JObject o) = return (M.keys o) fields j =