packages feed

JSON-Combinator 0.0.2 → 0.1.0

raw patch · 10 files changed

+1089/−655 lines, 10 filesdep +jsondep −HUnitdep −QuickCheckdep −test-frameworkPVP ok

version bump matches the API change (PVP)

Dependencies added: json

Dependencies removed: HUnit, QuickCheck, test-framework, test-framework-hunit, test-framework-quickcheck2

API changes (from Hackage documentation)

- Text.JSONb.Combinator: (-->>:) :: JSON -> JSON -> JSON
- Text.JSONb.Combinator: (->:) :: (ByteString, JSON) -> JSON -> JSON
- Text.JSONb.Combinator: (-?) :: ByteString -> JSON -> Bool
- Text.JSONb.Combinator: (-??) :: Foldable t => t ByteString -> JSON -> Bool
- Text.JSONb.Combinator: (-|) :: ByteString -> JSON -> Maybe JSON
- Text.JSONb.Combinator: (-||) :: Foldable t => t ByteString -> JSON -> Maybe JSON
- Text.JSONb.Combinator: arrayOr :: JArray -> JSON -> JArray
- Text.JSONb.Combinator: arrayOrEmpty :: JSON -> JArray
- Text.JSONb.Combinator: field :: ByteString -> JSON -> Maybe JSON
- Text.JSONb.Combinator: field' :: Foldable t => t ByteString -> JSON -> Maybe JSON
- Text.JSONb.Combinator: field'Or :: Foldable t => JSON -> t ByteString -> JSON -> JSON
- Text.JSONb.Combinator: field'OrEmptyArray :: Foldable t => t ByteString -> JSON -> JSON
- Text.JSONb.Combinator: field'OrEmptyObject :: Foldable t => t ByteString -> JSON -> JSON
- Text.JSONb.Combinator: field'OrEmptyString :: Foldable t => t ByteString -> JSON -> JSON
- Text.JSONb.Combinator: field'OrFalse :: Foldable t => t ByteString -> JSON -> JSON
- Text.JSONb.Combinator: field'OrNull :: Foldable t => t ByteString -> JSON -> JSON
- Text.JSONb.Combinator: field'OrTrue :: Foldable t => t ByteString -> JSON -> JSON
- Text.JSONb.Combinator: field'OrZero :: Foldable t => t ByteString -> JSON -> JSON
- Text.JSONb.Combinator: fieldOr :: ByteString -> JSON -> JSON -> JSON
- Text.JSONb.Combinator: fieldOrEmptyArray :: ByteString -> JSON -> JSON
- Text.JSONb.Combinator: fieldOrEmptyObject :: ByteString -> JSON -> JSON
- Text.JSONb.Combinator: fieldOrEmptyString :: ByteString -> JSON -> JSON
- Text.JSONb.Combinator: fieldOrFalse :: ByteString -> JSON -> JSON
- Text.JSONb.Combinator: fieldOrNull :: ByteString -> JSON -> JSON
- Text.JSONb.Combinator: fieldOrTrue :: ByteString -> JSON -> JSON
- Text.JSONb.Combinator: fieldOrZero :: ByteString -> JSON -> JSON
- Text.JSONb.Combinator: getArray :: JSON -> Maybe [JSON]
- Text.JSONb.Combinator: getBool :: JSON -> Maybe Bool
- Text.JSONb.Combinator: getNumber :: JSON -> Maybe Rational
- Text.JSONb.Combinator: getObject :: JSON -> Maybe (Trie JSON)
- Text.JSONb.Combinator: getObjectFields :: JSON -> Maybe [ByteString]
- Text.JSONb.Combinator: getObjectValues :: JSON -> Maybe [JSON]
- Text.JSONb.Combinator: getString :: JSON -> Maybe ByteString
- Text.JSONb.Combinator: hasField :: ByteString -> JSON -> Bool
- Text.JSONb.Combinator: hasField' :: Foldable t => t ByteString -> JSON -> Bool
- Text.JSONb.Combinator: interactJSON :: (Either String JSON -> JSON) -> IO ()
- Text.JSONb.Combinator: interactJSON' :: (String -> JSON) -> (JSON -> JSON) -> IO ()
- Text.JSONb.Combinator: interactJSONFile :: (Either String JSON -> JSON) -> FilePath -> FilePath -> IO ()
- Text.JSONb.Combinator: interactJSONFile' :: (String -> JSON) -> (JSON -> JSON) -> FilePath -> FilePath -> IO ()
- Text.JSONb.Combinator: isArray :: JSON -> Bool
- Text.JSONb.Combinator: isBool :: JSON -> Bool
- Text.JSONb.Combinator: isFalse :: JSON -> Bool
- Text.JSONb.Combinator: isNumber :: JSON -> Bool
- Text.JSONb.Combinator: isObject :: JSON -> Bool
- Text.JSONb.Combinator: isString :: JSON -> Bool
- Text.JSONb.Combinator: isTrue :: JSON -> Bool
- Text.JSONb.Combinator: jEmptyArray :: JSON
- Text.JSONb.Combinator: jEmptyObject :: JSON
- Text.JSONb.Combinator: jEmptyString :: JSON
- Text.JSONb.Combinator: jFalse :: JSON
- Text.JSONb.Combinator: jNot :: JSON -> JSON
- Text.JSONb.Combinator: jSingleArray :: JSON -> JSON
- Text.JSONb.Combinator: jSingleObject :: ByteString -> JSON -> JSON
- Text.JSONb.Combinator: jTrue :: JSON
- Text.JSONb.Combinator: jZero :: JSON
- Text.JSONb.Combinator: numberOr :: Rational -> JSON -> Rational
- Text.JSONb.Combinator: numberOrZero :: JSON -> Rational
- Text.JSONb.Combinator: objectFieldsOr :: [ByteString] -> JSON -> [ByteString]
- Text.JSONb.Combinator: objectFieldsOrEmpty :: JSON -> [ByteString]
- Text.JSONb.Combinator: objectOr :: Trie JSON -> JSON -> Trie JSON
- Text.JSONb.Combinator: objectOrEmpty :: JSON -> Trie JSON
- Text.JSONb.Combinator: objectValuesOr :: [JSON] -> JSON -> [JSON]
- Text.JSONb.Combinator: objectValuesOrEmpty :: JSON -> [JSON]
- Text.JSONb.Combinator: stringOr :: ByteString -> JSON -> ByteString
- Text.JSONb.Combinator: stringOrEmpty :: JSON -> ByteString
- Text.JSONb.Combinator: type JArray = [JSON]
- Text.JSONb.Combinator: type JObject = Trie JSON
- Text.JSONb.Combinator: usingArray :: a -> ([JSON] -> a) -> JSON -> a
- Text.JSONb.Combinator: usingNumber :: a -> (Rational -> a) -> JSON -> a
- Text.JSONb.Combinator: usingObject :: a -> (Trie JSON -> a) -> JSON -> a
- Text.JSONb.Combinator: usingObjectFields :: a -> ([ByteString] -> a) -> JSON -> a
- Text.JSONb.Combinator: usingObjectValues :: a -> ([JSON] -> a) -> JSON -> a
- Text.JSONb.Combinator: usingString :: a -> (ByteString -> a) -> JSON -> a
- Text.JSONb.Combinator: withArray :: (JArray -> JArray) -> JSON -> JSON
- Text.JSONb.Combinator: withJSON :: (String -> IO ()) -> (JSON -> JSON) -> IO ()
- Text.JSONb.Combinator: withJSONFile :: (String -> IO ()) -> (JSON -> JSON) -> FilePath -> FilePath -> IO ()
- Text.JSONb.Combinator: withNumber :: (Rational -> Rational) -> JSON -> JSON
- Text.JSONb.Combinator: withObject :: (JObject -> JObject) -> JSON -> JSON
- Text.JSONb.Combinator: withObjectFields :: (ByteString -> ByteString) -> JSON -> JSON
- Text.JSONb.Combinator: withObjectValues :: (JSON -> JSON) -> JSON -> JSON
- Text.JSONb.Combinator: withString :: (ByteString -> ByteString) -> JSON -> JSON
+ Text.JSON.Combinator: (-?) :: JSONField j f => f -> j -> Bool
+ Text.JSON.Combinator: (-??) :: (JSONField j f, Foldable t) => t f -> j -> Bool
+ Text.JSON.Combinator: (-|) :: JSONField j s => s -> j -> Maybe j
+ Text.JSON.Combinator: (-||) :: (JSONField j f, Foldable t) => t f -> j -> Maybe j
+ Text.JSON.Combinator: arrayOr :: JSONLike j s a o f => a j -> j -> a j
+ Text.JSON.Combinator: arrayOrEmpty :: (JSONLike j s a o f, Monoid (a j)) => j -> a j
+ Text.JSON.Combinator: field' :: (JSONField j f, Foldable t) => t f -> j -> Maybe j
+ Text.JSON.Combinator: field'Or :: (JSONField j f, Foldable t) => j -> t f -> j -> j
+ Text.JSON.Combinator: field'OrEmptyArray :: (JSONLike j s a o f, JSONField j f, Foldable t, Monoid (a j)) => t f -> j -> j
+ Text.JSON.Combinator: field'OrEmptyObject :: (JSONLike j s a o f, JSONField j f, Foldable t, Monoid (o j)) => t f -> j -> j
+ Text.JSON.Combinator: field'OrEmptyString :: (JSONLike j s a o f, JSONField j f, Foldable t, Monoid s) => t f -> j -> j
+ Text.JSON.Combinator: field'OrFalse :: (JSONLike j s a o f, JSONField j f, Foldable t) => t f -> j -> j
+ Text.JSON.Combinator: field'OrNull :: (JSONLike j s a o f, JSONField j f, Foldable t) => t f -> j -> j
+ Text.JSON.Combinator: field'OrTrue :: (JSONLike j s a o f, JSONField j f, Foldable t) => t f -> j -> j
+ Text.JSON.Combinator: field'OrZero :: (JSONLike j s a o f, JSONField j f, Foldable t) => t f -> j -> j
+ Text.JSON.Combinator: fieldOr :: JSONField j f => f -> j -> j -> j
+ Text.JSON.Combinator: fieldOrEmptyArray :: (JSONLike j s a o f, JSONField j f, Monoid (a j)) => f -> j -> j
+ Text.JSON.Combinator: fieldOrEmptyObject :: (JSONLike j s a o f, JSONField j f, Monoid (o j)) => f -> j -> j
+ Text.JSON.Combinator: fieldOrEmptyString :: (JSONLike j s a o f, JSONField j f, Monoid s) => f -> j -> j
+ Text.JSON.Combinator: fieldOrFalse :: (JSONLike j s a o f, JSONField j f) => f -> j -> j
+ Text.JSON.Combinator: fieldOrNull :: (JSONLike j s a o f, JSONField j f) => f -> j -> j
+ Text.JSON.Combinator: fieldOrTrue :: (JSONLike j s a o f, JSONField j f) => f -> j -> j
+ Text.JSON.Combinator: fieldOrZero :: (JSONLike j s a o f, JSONField j f) => f -> j -> j
+ Text.JSON.Combinator: fieldsOr :: JSONField j f => [f] -> j -> [f]
+ Text.JSON.Combinator: getArray :: JSONLike j s a o f => j -> Maybe (a j)
+ Text.JSON.Combinator: getBool :: JSONLike j s a o f => j -> Maybe Bool
+ Text.JSON.Combinator: getNumber :: JSONLike j s a o f => j -> Maybe Rational
+ Text.JSON.Combinator: getObject :: JSONLike j s a o f => j -> Maybe (o j)
+ Text.JSON.Combinator: getString :: JSONLike j s a o f => j -> Maybe s
+ Text.JSON.Combinator: hasField :: JSONField j f => f -> j -> Bool
+ Text.JSON.Combinator: hasField' :: (JSONField j f, Foldable t) => t f -> j -> Bool
+ Text.JSON.Combinator: interactJSON :: (JSONPrint j' s, JSONParse j s e, Interact s) => (Either e j -> j') -> IO ()
+ Text.JSON.Combinator: interactJSON' :: (JSONPrint j' s, JSONParse j s e, Interact s) => (e -> j') -> (j -> j') -> IO ()
+ Text.JSON.Combinator: interactJSONFile :: (InteractFile p, InteractFile s, JSONPrint j' s, JSONParse j p e) => (Either e j -> j') -> FilePath -> FilePath -> IO ()
+ Text.JSON.Combinator: interactJSONFile' :: (InteractFile p, InteractFile s, JSONPrint j' s, JSONParse j p e) => (e -> j') -> (j -> j') -> FilePath -> FilePath -> IO ()
+ Text.JSON.Combinator: isArray :: JSONLike j s a o f => j -> Bool
+ Text.JSON.Combinator: isBool :: JSONLike j s a o f => j -> Bool
+ Text.JSON.Combinator: isFalse :: JSONLike j s a o f => j -> Bool
+ Text.JSON.Combinator: isNumber :: JSONLike j s a o f => j -> Bool
+ Text.JSON.Combinator: isObject :: JSONLike j s a o f => j -> Bool
+ Text.JSON.Combinator: isString :: JSONLike j s a o f => j -> Bool
+ Text.JSON.Combinator: isTrue :: JSONLike j s a o f => j -> Bool
+ Text.JSON.Combinator: jemptyarray :: (Monoid (a j), JSONLike j s a o f) => j
+ Text.JSON.Combinator: jemptyobject :: (Monoid (o j), JSONLike j s a o f) => j
+ Text.JSON.Combinator: jemptystring :: (Monoid s, JSONLike j s a o f) => j
+ Text.JSON.Combinator: jnot :: JSONLike j s a o f => j -> j
+ Text.JSON.Combinator: jsinglearray :: (Applicative a, JSONLike j s a o f) => j -> j
+ Text.JSON.Combinator: jsingleobject :: (Applicative o, JSONLike j s a o f) => j -> j
+ Text.JSON.Combinator: jzero :: JSONLike j s a o f => j
+ Text.JSON.Combinator: numberOr :: JSONLike j s a o f => Rational -> j -> Rational
+ Text.JSON.Combinator: numberOrZero :: JSONLike j s a o f => j -> Rational
+ Text.JSON.Combinator: objectFieldsOrEmpty :: (JSONField j f, Monoid (o j)) => j -> [f]
+ Text.JSON.Combinator: objectOr :: JSONLike j s a o f => o j -> j -> o j
+ Text.JSON.Combinator: objectOrEmpty :: (JSONLike j s a o f, Monoid (o j)) => j -> o j
+ Text.JSON.Combinator: objectValuesOrEmpty :: (JSONField j f, Monoid (o j)) => j -> [j]
+ Text.JSON.Combinator: stringOr :: JSONLike j s a o f => s -> j -> s
+ Text.JSON.Combinator: stringOrEmpty :: (JSONLike j s a o f, Monoid s) => j -> s
+ Text.JSON.Combinator: usingArray :: JSONLike j s a o f => x -> (a j -> x) -> j -> x
+ Text.JSON.Combinator: usingNumber :: JSONLike j s a o f => x -> (Rational -> x) -> j -> x
+ Text.JSON.Combinator: usingObject :: JSONLike j s a o f => x -> (o j -> x) -> j -> x
+ Text.JSON.Combinator: usingObjectFields :: JSONField j f => a -> ([f] -> a) -> j -> a
+ Text.JSON.Combinator: usingObjectValues :: JSONField j f => a -> ([j] -> a) -> j -> a
+ Text.JSON.Combinator: usingString :: JSONLike j s a o f => x -> (s -> x) -> j -> x
+ Text.JSON.Combinator: valuesOr :: JSONField j f => [j] -> j -> [j]
+ Text.JSON.Combinator: withArray :: JSONLike j s a o f => (a j -> a j) -> j -> j
+ Text.JSON.Combinator: withJSON :: (Interact p, Interact s, JSONPrint j' s, JSONParse j p e) => (e -> IO ()) -> (j -> j') -> IO ()
+ Text.JSON.Combinator: withJSONFile :: (InteractFile p, InteractFile s, JSONPrint j' s, JSONParse j p e) => (e -> IO ()) -> (j -> j') -> FilePath -> FilePath -> IO ()
+ Text.JSON.Combinator: withNumber :: JSONLike j s a o f => (Rational -> Rational) -> j -> j
+ Text.JSON.Combinator: withObject :: JSONLike j s a o f => (o j -> o j) -> j -> j
+ Text.JSON.Combinator: withObjectFields :: (Functor o, JSONLike j s a o f) => (j -> j) -> j -> j
+ Text.JSON.Combinator: withString :: JSONLike j s a o f => (s -> s) -> j -> j
+ Text.JSON.Interact: class Interact z
+ Text.JSON.Interact: getContents' :: Interact z => IO z
+ Text.JSON.Interact: instance Interact ByteString
+ Text.JSON.Interact: instance Interact [Char]
+ Text.JSON.Interact: interact' :: Interact z => (z -> z) -> IO ()
+ Text.JSON.Interact: putStr' :: Interact z => z -> IO ()
+ Text.JSON.InteractFile: class InteractFile z
+ Text.JSON.InteractFile: instance InteractFile ByteString
+ Text.JSON.InteractFile: instance InteractFile [Char]
+ Text.JSON.InteractFile: readFile' :: InteractFile z => FilePath -> IO z
+ Text.JSON.InteractFile: writeFile' :: InteractFile z => FilePath -> z -> IO ()
+ Text.JSON.JSONField: class JSONField j f | j -> f
+ Text.JSON.JSONField: field :: JSONField j f => f -> j -> Maybe j
+ Text.JSON.JSONField: fields :: JSONField j f => j -> Maybe [f]
+ Text.JSON.JSONField: instance JSONField JSON ByteString
+ Text.JSON.JSONField: instance JSONField JSValue [Char]
+ Text.JSON.JSONField: values :: JSONField j f => j -> Maybe [j]
+ Text.JSON.JSONLike: class JSONLike j s a o f | j -> s, j -> a, j -> o, o -> f
+ Text.JSON.JSONLike: foldJSON :: JSONLike j s a o f => x -> x -> x -> (Rational -> x) -> (s -> x) -> (a j -> x) -> (o j -> x) -> j -> x
+ Text.JSON.JSONLike: instance JSONLike JSON ByteString [] Trie ByteString
+ Text.JSON.JSONLike: instance JSONLike JSValue [Char] [] JSObject [Char]
+ Text.JSON.JSONLike: jarray :: JSONLike j s a o f => a j -> j
+ Text.JSON.JSONLike: jfalse :: JSONLike j s a o f => j
+ Text.JSON.JSONLike: jnull :: JSONLike j s a o f => j
+ Text.JSON.JSONLike: jnumber :: JSONLike j s a o f => Rational -> j
+ Text.JSON.JSONLike: jobject :: JSONLike j s a o f => o j -> j
+ Text.JSON.JSONLike: jstring :: JSONLike j s a o f => s -> j
+ Text.JSON.JSONLike: jtrue :: JSONLike j s a o f => j
+ Text.JSON.JSONParse: class JSONParse j p e | j -> p, j -> e
+ Text.JSON.JSONParse: instance JSONParse JSON ByteString [Char]
+ Text.JSON.JSONParse: instance JSONParse JSValue [Char] ParseError
+ Text.JSON.JSONParse: parseJSON :: JSONParse j p e => String -> p -> Either e j
+ Text.JSON.JSONParse: parseJSON' :: JSONParse j p e => p -> Either e j
+ Text.JSON.JSONPrepend: (-->>:) :: JSONPrepend j s => j -> j -> j
+ Text.JSON.JSONPrepend: (->:) :: JSONPrepend j s => (s, j) -> j -> j
+ Text.JSON.JSONPrepend: class JSONPrepend j s | j -> s
+ Text.JSON.JSONPrepend: instance JSONPrepend JSON ByteString
+ Text.JSON.JSONPrepend: instance JSONPrepend JSValue [Char]
+ Text.JSON.JSONPrint: class JSONPrint j s | j -> s
+ Text.JSON.JSONPrint: instance JSONPrint JSON ByteString
+ Text.JSON.JSONPrint: instance JSONPrint JSValue [Char]
+ Text.JSON.JSONPrint: printJSON :: JSONPrint j s => j -> s

Files

JSON-Combinator.cabal view
@@ -1,12 +1,20 @@ Name:               JSON-Combinator-Version:            0.0.2+Version:            0.1.0 License:            BSD3 License-File:       LICENSE Author:             Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> Maintainer:         Tony Morris-Synopsis:           A combinator library on top of Text.JSONb+Synopsis:           A combinator library on top of a generalised JSON type Category:           Combinator-Description:        A combinator library on top of Text.JSONb +Description:+  A combinator library on top of a generalised JSON type. The highest-level module is+  @Text.JSON.Combinator@ and it is expected that no other module need to be explicitly imported.+  .+  Instances for the combinators are provided for two libraries available on hackage:+  .+    * json (@Text.JSON@)+    .+    * JSONb (@Text.JSONb@) Cabal-version:      >= 1.2 Build-Type:         Simple @@ -14,19 +22,20 @@   Description:      Choose the new, split-up base package.  Library-  Build-Depends:    base < 5 && >= 4,-                    JSONb,-                    bytestring,-                    bytestring-trie,-                    HUnit,-                    QuickCheck,-                    test-framework,-                    test-framework-hunit,-                    test-framework-quickcheck2+  Build-Depends:+                    base < 5 && >= 4+                    , JSONb+                    , json+                    , bytestring+                    , bytestring-trie    GHC-Options:      -Wall-                    -fno-warn-orphans-                    -fno-warn-type-defaults-                    -fno-warn-name-shadowing -  Exposed-Modules:  Text.JSONb.Combinator+  Exposed-Modules:  Text.JSON.Combinator+                    , Text.JSON.JSONLike+                    , Text.JSON.JSONField+                    , Text.JSON.JSONPrepend+                    , Text.JSON.JSONParse+                    , Text.JSON.JSONPrint+                    , Text.JSON.Interact+                    , Text.JSON.InteractFile
+ Text/JSON/Combinator.hs view
@@ -0,0 +1,731 @@+-- | Combinators for JSON data types.+module Text.JSON.Combinator+(+  -- * Transformers+  jnot+, withNumber+, withString+, withArray+, withObject+, withObjectFields+  -- * Constructors+, jzero+, jemptystring+, jemptyarray+, jemptyobject+, jsinglearray+, jsingleobject+  -- * Accessors+, getBool+, getNumber+, getString+, getArray+, getObject+  -- * Decisions+, isBool+, isTrue+, isFalse+, isNumber+, isString+, isArray+, isObject+  -- * Accessors with default+, numberOr+, stringOr+, arrayOr+, objectOr+, fieldsOr+, valuesOr+, numberOrZero+, stringOrEmpty+, arrayOrEmpty+, objectOrEmpty+, objectFieldsOrEmpty+, objectValuesOrEmpty+  -- * Combinators+, usingNumber+, usingString+, usingArray+, usingObject+, usingObjectFields+, usingObjectValues+  -- * Object field accessors+, hasField+, (-?)+, (-|)+, fieldOr+, fieldOrNull+, fieldOrTrue+, fieldOrFalse+, fieldOrZero+, fieldOrEmptyString+, fieldOrEmptyArray+, fieldOrEmptyObject+, hasField'+, (-??)+, field'+, (-||)+, field'Or+, field'OrNull+, field'OrTrue+, field'OrFalse+, field'OrZero+, field'OrEmptyString+, field'OrEmptyArray+, field'OrEmptyObject+  -- * Stdin/stdout interaction+, interactJSON+, interactJSON'+, withJSON+  -- * File I/O+, interactJSONFile+, interactJSONFile'+, withJSONFile+  -- * Modules containing additional combinators+, module Text.JSON.JSONLike+, module Text.JSON.JSONField+, module Text.JSON.JSONParse+, module Text.JSON.JSONPrepend+, module Text.JSON.JSONPrint+) where++import Text.JSON.JSONLike+import Text.JSON.JSONField+import Text.JSON.JSONParse+import Text.JSON.JSONPrepend+import Text.JSON.JSONPrint+import Text.JSON.Interact+import Text.JSON.InteractFile+import Control.Applicative+import Data.Maybe+import Data.Monoid+import qualified Data.Foldable as F++-- | Returns whether or not a JSON is a boolean with the value true.+isTrue ::+  JSONLike j s a o f =>+  j -- ^ The JSON value.+  -> Bool+isTrue =+  foldJSON False True False (const False) (const False) (const False) (const False)++-- | Returns whether or not a JSON is a boolean with the value false.+isFalse ::+  JSONLike j s a o f =>+  j -- ^ The JSON value.+  -> Bool+isFalse =+  foldJSON False False True (const False) (const False) (const False) (const False)++-- | Returns whether or not a JSON is a boolean value.+isBool ::+  JSONLike j s a o f =>+  j -- ^ The JSON value.+  -> Bool+isBool =+  liftA2 (||) isTrue isFalse++-- | Returns whether or not a JSON is a number value.+isNumber ::+  JSONLike j s a o f =>+  j -- ^ The JSON value.+  -> Bool+isNumber =+  foldJSON False False False (const True) (const False) (const False) (const False)++-- | Returns whether or not a JSON is a string value.+isString ::+  JSONLike j s a o f =>+  j -- ^ The JSON value.+  -> Bool+isString =+  foldJSON False False False (const False) (const True) (const False) (const False)++-- | Returns whether or not a JSON is an array value.+isArray ::+  JSONLike j s a o f =>+  j -- ^ The JSON value.+  -> Bool+isArray =+  foldJSON False False False (const False) (const False) (const True) (const False)++-- | Returns whether or not a JSON is an object value.+isObject ::+  JSONLike j s a o f =>+  j -- ^ The JSON value.+  -> Bool+isObject =+  foldJSON False False False (const False) (const False) (const False) (const True)++-- | Inverts the JSON value if it is a boolean.+jnot ::+  JSONLike j s a o f =>+  j -- ^ The JSON value.+  -> j+jnot j =+  if isTrue j+    then jfalse+    else+      if isFalse j+        then+          jtrue+        else+          j++-- | Runs the given function if the JSON value is a number.+withNumber ::+  JSONLike j s a o f =>+  (Rational -> Rational)+  -> j -- ^ The JSON value.+  -> j+withNumber f j =+  foldJSON j j j (jnumber . f) (const j) (const j) (const j) j++-- | Runs the given function if the JSON value is a string.+withString ::+  JSONLike j s a o f =>+  (s -> s)+  -> j -- ^ The JSON value.+  -> j+withString f j =+  foldJSON j j j (const j) (jstring . f) (const j) (const j) j++-- | Runs the given function if the JSON value is an array.+withArray ::+  JSONLike j s a o f =>+  (a j -> a j)+  -> j -- ^ The JSON value.+  -> j+withArray f j =+  foldJSON j j j (const j) (const j) (jarray . f) (const j) j++-- | Runs the given function if the JSON value is an object.+withObject ::+  JSONLike j s a o f =>+  (o j -> o j)+  -> j -- ^ The JSON value.+  -> j+withObject f j =+  foldJSON j j j (const j) (const j) (const j) (jobject . f) j++-- | Runs the given function on the fields if the JSON value is an object.+withObjectFields ::+  (Functor o, JSONLike j s a o f) =>+  (j -> j)+  -> j -- ^ The JSON value.+  -> j+withObjectFields f =+  withObject (fmap f)++-- | Returns the potential boolean value of a JSON value.+getBool ::+  JSONLike j s a o f =>+  j -- ^ The JSON value.+  -> Maybe Bool+getBool =+  foldJSON Nothing (Just True) (Just False) (const Nothing) (const Nothing) (const Nothing) (const Nothing)++-- | Returns the potential number value of a JSON value.+getNumber ::+  JSONLike j s a o f =>+  j -- ^ The JSON value.+  -> Maybe Rational+getNumber =+  foldJSON Nothing Nothing Nothing Just (const Nothing) (const Nothing) (const Nothing)++-- | Returns the potential string value of a JSON value.+getString ::+  JSONLike j s a o f =>+  j -- ^ The JSON value.+  -> Maybe s+getString =+  foldJSON Nothing Nothing Nothing (const Nothing) Just (const Nothing) (const Nothing)++-- | Returns the potential array value of a JSON value.+getArray ::+  JSONLike j s a o f =>+  j -- ^ The JSON value.+  -> Maybe (a j)+getArray =+  foldJSON Nothing Nothing Nothing (const Nothing) (const Nothing) Just (const Nothing)++-- | Returns the potential object value of a JSON value.+getObject ::+  JSONLike j s a o f =>+  j -- ^ The JSON value.+  -> Maybe (o j)+getObject =+  foldJSON Nothing Nothing Nothing (const Nothing) (const Nothing) (const Nothing) Just++-- | Returns a number value from a JSON value or if it is not a number, returns the given default.+numberOr ::+  JSONLike j s a o f =>+  Rational+  -> j -- ^ The JSON value.+  -> Rational+numberOr x =+  fromMaybe x . getNumber++-- | Returns a string value from a JSON value or if it is not a string, returns the given default.+stringOr ::+  JSONLike j s a o f =>+  s+  -> j -- ^ The JSON value.+  -> s+stringOr x =+  fromMaybe x . getString++-- | Returns a rational value from a JSON value or if it is not a rational, returns the given default.+arrayOr ::+  JSONLike j s a o f =>+  a j+  -> j -- ^ The JSON value.+  -> a j+arrayOr x =+  fromMaybe x . getArray++-- | Returns an object value from a JSON value or if it is not an object, returns the given default.+objectOr ::+  JSONLike j s a o f =>+  o j+  -> j -- ^ The JSON value.+  -> o j+objectOr x =+  fromMaybe x . getObject++-- | Returns an object's fields from a JSON value or if it is not an object, returns the given default.+fieldsOr ::+  JSONField j f =>+  [f]+  -> j -- ^ The JSON value.+  -> [f]+fieldsOr x =+  fromMaybe x . fields++-- | Returns an object's values from a JSON value or if it is not an object, returns the given default.+valuesOr ::+  JSONField j f =>+  [j]+  -> j -- ^ The JSON value.+  -> [j]+valuesOr x =+  fromMaybe x . values++-- | Runs a function on the number of a JSON value or if it is not a number, returns the given default.+usingNumber ::+  JSONLike j s a o f =>+  x+  -> (Rational -> x)+  -> j -- ^ The JSON value.+  -> x+usingNumber a f =+  maybe a f . getNumber++-- | Runs a function on the string of a JSON value or if it is not a string, returns the given default.+usingString ::+  JSONLike j s a o f =>+  x+  -> (s -> x)+  -> j -- ^ The JSON value.+  -> x+usingString a f =+  maybe a f . getString++-- | Runs a function on the array of a JSON value or if it is not an array, returns the given default.+usingArray ::+  JSONLike j s a o f =>+  x+  -> (a j -> x)+  -> j -- ^ The JSON value.+  -> x+usingArray a f =+  maybe a f . getArray++-- | Runs a function on the object of a JSON value or if it is not an object, returns the given default.+usingObject ::+  JSONLike j s a o f =>+  x+  -> (o j -> x)+  -> j -- ^ The JSON value.+  -> x+usingObject a f =+  maybe a f . getObject++-- | Runs a function on the fields of an object of a JSON value or if it is not an object, returns the given default.+usingObjectFields ::+  JSONField j f =>+  a+  -> ([f] -> a)+  -> j -- ^ The JSON value.+  -> a+usingObjectFields a f =+  maybe a f . fields++-- | Runs a function on the values of an object of a JSON value or if it is not an object, returns the given default.+usingObjectValues ::+  JSONField j f =>+  a+  -> ([j] -> a)+  -> j -- ^ The JSON value.+  -> a+usingObjectValues a f =+  maybe a f . values++-- | The JSON value zero.+jzero ::+  JSONLike j s a o f =>+  j+jzero =+  jnumber 0++-- | The JSON value empty string.+jemptystring ::+  (Monoid s, JSONLike j s a o f) =>+  j+jemptystring =+  jstring mempty++-- | The JSON value empty array.+jemptyarray ::+  (Monoid (a j), JSONLike j s a o f) =>+  j+jemptyarray =+  jarray mempty++-- | The JSON value empty object.+jemptyobject ::+  (Monoid (o j), JSONLike j s a o f) =>+  j+jemptyobject =+  jobject mempty++-- | Puts a single value into a JSON array.+jsinglearray ::+  (Applicative a, JSONLike j s a o f) =>+  j+  -> j+jsinglearray =+  jarray . pure++-- | Puts a single value into a JSON object.+jsingleobject ::+  (Applicative o, JSONLike j s a o f) =>+  j+  -> j+jsingleobject =+  jobject . pure++-- | Returns the possible value associated with the given field if this is an object. An alias for 'field'.+(-|) ::+  JSONField j s =>+  s+  -> j -- ^ The JSON value.+  -> Maybe j+(-|) =+  field++-- | Returns a number value from a JSON value or if it is not a number, returns zero.+numberOrZero ::+  JSONLike j s a o f =>+  j -- ^ The JSON value.+  -> Rational+numberOrZero =+  numberOr 0++-- | Returns a string value from a JSON value or if it is not a string, returns an empty string.+stringOrEmpty ::+  (JSONLike j s a o f, Monoid s) =>+  j -- ^ The JSON value.+  -> s+stringOrEmpty =+  stringOr mempty++-- | Returns an array value from a JSON value or if it is not an array, returns an empty array.+arrayOrEmpty ::+  (JSONLike j s a o f, Monoid (a j)) =>+  j -- ^ The JSON value.+  -> a j+arrayOrEmpty =+  arrayOr mempty++-- | Returns an object value from a JSON value or if it is not an object, returns an empty object.+objectOrEmpty ::+  (JSONLike j s a o f, Monoid (o j)) =>+  j -- ^ The JSON value.+  -> o j+objectOrEmpty =+  objectOr mempty++-- | Returns an object's fields from a JSON value or if it is not an object, returns no fields.+objectFieldsOrEmpty ::+  (JSONField j f, Monoid (o j)) =>+  j -- ^ The JSON value.+  -> [f]+objectFieldsOrEmpty =+  fieldsOr []++-- | Returns an object's values from a JSON value or if it is not an object, returns no values.+objectValuesOrEmpty ::+  (JSONField j f, Monoid (o j)) =>+  j -- ^ The JSON value.+  -> [j]+objectValuesOrEmpty =+  valuesOr []++-- | Whether or not a JSON value is an object with the given field.+hasField ::+  JSONField j f =>+  f+  -> j -- ^ The JSON value.+  -> Bool+hasField s =+  isJust . field s++-- | Whether or not a JSON value is an object with the given field. An alias for 'hasField'.+(-?) ::+  JSONField j f =>+  f+  -> j -- ^ The JSON value.+  -> Bool+(-?) =+  hasField++-- | Returns the value associated with the given field or if this is not an object or has no associated value, return the given default.+fieldOr ::+  JSONField j f =>+  f+  -> j -- ^ The default.+  -> j -- ^ The JSON value.+  -> j+fieldOr s =+  flip fromMaybe . field s++-- | Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON null.+fieldOrNull ::+  (JSONLike j s a o f, JSONField j f) =>+  f+  -> j -- ^ The JSON value.+  -> j+fieldOrNull s j =+  fieldOr s j jnull++-- | Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON true.+fieldOrTrue ::+  (JSONLike j s a o f, JSONField j f) =>+  f+  -> j -- ^ The JSON value.+  -> j+fieldOrTrue s j =+  fieldOr s j jtrue++-- | Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON false.+fieldOrFalse ::+  (JSONLike j s a o f, JSONField j f) =>+  f+  -> j -- ^ The JSON value.+  -> j+fieldOrFalse s j =+  fieldOr s j jfalse++-- | Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON zero.+fieldOrZero ::+  (JSONLike j s a o f, JSONField j f) =>+  f+  -> j -- ^ The JSON value.+  -> j+fieldOrZero s j =+  fieldOr s j jzero++-- | Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON string that is empty.+fieldOrEmptyString ::+  (JSONLike j s a o f, JSONField j f, Monoid s) =>+  f+  -> j -- ^ The JSON value.+  -> j+fieldOrEmptyString s j =+  fieldOr s j jemptystring++-- | Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON array that is empty.+fieldOrEmptyArray ::+  (JSONLike j s a o f, JSONField j f, Monoid (a j)) =>+  f+  -> j -- ^ The JSON value.+  -> j+fieldOrEmptyArray s j =+  fieldOr s j jemptyarray++-- | Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON object that is empty.+fieldOrEmptyObject ::+  (JSONLike j s a o f, JSONField j f, Monoid (o j)) =>+  f+  -> j -- ^ The JSON value.+  -> j+fieldOrEmptyObject s j =+  fieldOr s j jemptyobject++-- | Traverses down JSON objects with the association fields and returns the potential value.+field' ::+  (JSONField j f, F.Foldable t) =>+  t f+  -> j -- ^ The JSON value.+  -> Maybe j+field' =+  flip (F.foldrM field)++-- | Traverses down JSON objects with the association fields and returns the potential value. An alias for 'field''.+(-||) ::+  (JSONField j f, F.Foldable t) =>+  t f+  -> j -- ^ The JSON value.+  -> Maybe j+(-||) =+  field'++-- | Traverses down JSON objects with the association fields and returns true if the association graph exists.+hasField' ::+  (JSONField j f, F.Foldable t) =>+  t f+  -> j -- ^ The JSON value.+  -> Bool+hasField' s =+  isJust . field' s++-- | Traverses down JSON objects with the association fields and returns true if the association graph exists. An alias for 'hasField''.+(-??) ::+  (JSONField j f, F.Foldable t) =>+  t f+  -> j -- ^ The JSON value.+  -> Bool+(-??) =+  hasField'++-- | Traverses down JSON objects with the association fields and returns the potential value or the given default.+field'Or ::+  (JSONField j f, F.Foldable t) =>+  j -- ^ The default.+  -> t f+  -> j -- ^ The JSON value.+  -> j+field'Or d s =+  fromMaybe d . field' s++-- | Traverses down JSON objects with the association fields and returns the potential value or a JSON null.+field'OrNull ::+  (JSONLike j s a o f, JSONField j f, F.Foldable t) =>+  t f+  -> j -- ^ The JSON value.+  -> j+field'OrNull =+  field'Or jnull++-- | Traverses down JSON objects with the association fields and returns the potential value or a JSON true.+field'OrTrue ::+  (JSONLike j s a o f, JSONField j f, F.Foldable t) =>+  t f+  -> j -- ^ The JSON value.+  -> j+field'OrTrue =+  field'Or jtrue++-- | Traverses down JSON objects with the association fields and returns the potential value or a JSON false.+field'OrFalse ::+  (JSONLike j s a o f, JSONField j f, F.Foldable t) =>+  t f+  -> j -- ^ The JSON value.+  -> j+field'OrFalse =+  field'Or jfalse++-- | Traverses down JSON objects with the association fields and returns the potential value or a JSON zero.+field'OrZero ::+  (JSONLike j s a o f, JSONField j f, F.Foldable t) =>+  t f+  -> j -- ^ The JSON value.+  -> j+field'OrZero =+  field'Or jzero++-- | Traverses down JSON objects with the association fields and returns the potential value or a JSON empty string.+field'OrEmptyString ::+  (JSONLike j s a o f, JSONField j f, F.Foldable t, Monoid s) =>+  t f+  -> j -- ^ The JSON value.+  -> j+field'OrEmptyString =+  field'Or jemptystring++-- | Traverses down JSON objects with the association fields and returns the potential value or a JSON empty array.+field'OrEmptyArray ::+  (JSONLike j s a o f, JSONField j f, F.Foldable t, Monoid (a j)) =>+  t f+  -> j -- ^ The JSON value.+  -> j+field'OrEmptyArray =+  field'Or jemptyarray++-- | Traverses down JSON objects with the association fields and returns the potential value or a JSON empty object.+field'OrEmptyObject ::+  (JSONLike j s a o f, JSONField j f, F.Foldable t, Monoid (o j)) =>+  t f+  -> j -- ^ The JSON value.+  -> j+field'OrEmptyObject =+  field'Or jemptyobject++-- | Interacts by parsing the standard input for JSON, passing the result to the given function, then printing the result to standard output.+interactJSON ::+  (JSONPrint j' s, JSONParse j s e, Interact s) =>+  (Either e j -> j')+  -> IO ()+interactJSON f =+  interact' (printJSON . f . parseJSON "stdin")++-- | Interacts by parsing the standard input for JSON, passing a failed result with a string error message to the given function, or a successful result to the given function, then printing the result to standard output.+interactJSON' ::+  (JSONPrint j' s, JSONParse j s e, Interact s) =>+  (e -> j')+  -> (j -> j')+  -> IO ()+interactJSON' l =+  interactJSON . either l++-- | Interacts by parsing the standard input for JSON, executing the given function for a failed result with a string error message, or printing a successful result to the given function and passing the result to standard output.+withJSON ::+ (Interact p, Interact s, JSONPrint j' s, JSONParse j p e) =>+  (e -> IO ())+  -> (j -> j')+  -> IO ()+withJSON f g =+  getContents' >>= either f (putStr' . printJSON . g) . parseJSON "stdin"++-- | Interacts by parsing the given file for JSON, passing the result to the given function, then writing the result to the given file.+interactJSONFile ::+  (InteractFile p, InteractFile s, JSONPrint j' s, JSONParse j p e) =>+  (Either e j -> j')+  -> FilePath+  -> FilePath+  -> IO ()+interactJSONFile f i o =+  readFile' i >>= writeFile' o . (printJSON . f) . parseJSON ""++-- | Interacts by parsing the given file for JSON, passing a failed result with a string error message to the given function, or a successful result to the given function, then writing the result to the given file.+interactJSONFile' ::+  (InteractFile p, InteractFile s, JSONPrint j' s, JSONParse j p e) =>+  (e -> j')+  -> (j -> j')+  -> FilePath+  -> FilePath+  -> IO ()+interactJSONFile' l =+  interactJSONFile . either l++-- | Interacts by parsing the given file for JSON, executing the given function for a failed result with a string error message, or printing a successful result to the given function and writing the result to the given file.+withJSONFile ::+  (InteractFile p, InteractFile s, JSONPrint j' s, JSONParse j p e) =>+  (e -> IO ())+  -> (j -> j')+  -> FilePath+  -> FilePath+  -> IO ()+withJSONFile f g i o =+  readFile' i >>= either f (writeFile' o . printJSON . g) . parseJSON i
+ Text/JSON/Interact.hs view
@@ -0,0 +1,35 @@+{-# LANGUAGE FlexibleInstances #-}++-- | A generalisation on functions to interact with standard input and standard output.+module Text.JSON.Interact+(+  Interact(..)+) where++import Data.ByteString+import qualified Data.ByteString as S++class Interact z where+  getContents' ::+    IO z+  putStr' ::+    z -> IO ()++  interact' ::+    (z -> z)+    -> IO ()+  interact' t =+    putStr' . t =<< getContents'++instance Interact [Char] where+  getContents' =+    Prelude.getContents+  putStr' =+    Prelude.putStr++instance Interact ByteString where+  getContents' =+    S.getContents+  putStr' =+    S.putStr+
+ Text/JSON/InteractFile.hs view
@@ -0,0 +1,32 @@+{-# LANGUAGE FlexibleInstances #-}++-- | A generalisation on functions to read and write files.+module Text.JSON.InteractFile+(+  InteractFile(..)+) where++import Data.ByteString+import qualified Data.ByteString as S++class InteractFile z where+  readFile' ::+    FilePath+    -> IO z+  writeFile' ::+    FilePath+    -> z+    -> IO ()++instance InteractFile [Char] where+  readFile' =+    Prelude.readFile+  writeFile' =+    Prelude.writeFile++instance InteractFile ByteString where+  readFile' =+    S.readFile+  writeFile' =+    S.writeFile+
+ Text/JSON/JSONField.hs view
@@ -0,0 +1,54 @@+{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FunctionalDependencies #-}++-- | The base functions for accessing JSON object fields.+module Text.JSON.JSONField+(+  JSONField(..)+) where++import Data.ByteString+import qualified Data.Trie as T+import Text.JSONb+import qualified Text.JSON as J+import Text.JSON.Types++class JSONField j f | j -> f where+  field ::+    f+    -> j+    -> Maybe j+  fields ::+    j+    -> Maybe [f]+  -- | Returns the potential object field values of a JSON value.+  values ::+    j+    -> Maybe [j]++instance JSONField JSON ByteString where+  field f (Object o) =+    T.lookup f o+  field _ _ =+    Nothing+  fields (Object o) =+    Just (T.keys o)+  fields _ =+    Nothing+  values (Object o) =+    Just . fmap snd . T.toList $ o+  values _ =+    Nothing++instance JSONField J.JSValue [Char] where+  field f (J.JSObject (JSONObject o)) =+    lookup f o+  field _ _ =+    Nothing+  fields (J.JSObject (JSONObject o)) =+    Just (fmap fst o)+  fields _ =+    Nothing+  values (J.JSObject (JSONObject o)) =+    Just (fmap snd o)+  values _ =+    Nothing
+ Text/JSON/JSONLike.hs view
@@ -0,0 +1,108 @@+{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FunctionalDependencies #-}++-- | The generalisation of a JSON object.+module Text.JSON.JSONLike+(+  JSONLike(..)+) where++import Data.ByteString+import qualified Data.Trie as T+import Text.JSONb+import qualified Text.JSON as J+import Text.JSON.Types++-- | The generalisation of a JSON object.+class JSONLike j s a o f | j -> s, j -> a, j -> o, o -> f where+  -- | Deconstructs a JSON object.+  foldJSON ::+    x -- ^ If a JSON null value.+    -> x -- ^ If a JSON true value.+    -> x -- ^ If a JSON false value.+    -> (Rational -> x) -- ^ If a JSON number value.+    -> (s -> x) -- ^ If a JSON string value.+    -> (a j -> x) -- ^ If a JSON array value.+    -> (o j -> x) -- ^ If a JSON object value.+    -> j+    -> x+  -- | Constructs a JSON null value.+  jnull ::+    j+  -- | Constructs a JSON true value.+  jtrue ::+    j+  -- | Constructs a JSON false value.+  jfalse ::+    j+  -- | Constructs a JSON number value from the given rational.+  jnumber ::+    Rational+    -> j+  -- | Constructs a JSON string value from the given string.+  jstring ::+    s+    -> j+  -- | Constructs a JSON array value from the given array.+  jarray ::+    a j+    -> j+  -- | Constructs a JSON object value from the given object.+  jobject ::+    o j+    -> j++instance JSONLike JSON ByteString [] T.Trie ByteString where+  foldJSON n _ _ _ _ _ _ Null =+    n+  foldJSON _ t f _ _ _ _ (Boolean b) =+    if b then t else f+  foldJSON _ _ _ r _ _ _ (Number r') =+    r r'+  foldJSON _ _ _ _ s _ _ (String s') =+    s s'+  foldJSON _ _ _ _ _ a _ (Array a') =+    a a'+  foldJSON _ _ _ _ _ _ o (Object o') =+    o o'+  jnull =+    Null+  jtrue =+    Boolean True+  jfalse =+    Boolean False+  jnumber =+    Number+  jstring =+    String+  jarray =+    Array+  jobject =+    Object++instance JSONLike J.JSValue [Char] [] J.JSObject [Char] where+  foldJSON n _ _ _ _ _ _ J.JSNull =+    n+  foldJSON _ t f _ _ _ _ (J.JSBool b) =+    if b then t else f+  foldJSON _ _ _ r _ _ _ (J.JSRational _ r') =+    r r'+  foldJSON _ _ _ _ s _ _ (J.JSString (JSONString s')) =+    s s'+  foldJSON _ _ _ _ _ a _ (J.JSArray a') =+    a a'+  foldJSON _ _ _ _ _ _ o (J.JSObject o') =+    o o'+  jnull =+    J.JSNull+  jtrue =+    J.JSBool True+  jfalse =+    J.JSBool False+  jnumber =+    J.JSRational False+  jstring =+    J.JSString . JSONString+  jarray =+    J.JSArray+  jobject =+    J.JSObject
+ Text/JSON/JSONParse.hs view
@@ -0,0 +1,38 @@+{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FunctionalDependencies #-}++-- | Parsing JSON object values.+module Text.JSON.JSONParse+(+  JSONParse(..)+, parseJSON'+) where++import Data.ByteString+import Text.JSONb+import qualified Text.JSON as J+import Text.JSON.Parsec++-- | Parsing JSON object values.+class JSONParse j p e | j -> p, j -> e where+  -- | Parses a value into either an error or a JSON object.+  parseJSON ::+    String -- ^ Source name.+    -> p -- ^ The value to parse.+    -> Either e j -- ^ Either error or a JSON object.++instance JSONParse JSON ByteString [Char] where+  parseJSON =+    const decode++instance JSONParse J.JSValue [Char] ParseError where+  parseJSON =+    parse p_jvalue++-- | Parse a value with an empty source name.+parseJSON' ::+  JSONParse j p e =>+  p -- ^ The value to parse.+  -> Either e j -- ^ Either error or a JSON object.+parseJSON' =+  parseJSON []+
+ Text/JSON/JSONPrepend.hs view
@@ -0,0 +1,38 @@+{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FunctionalDependencies #-}++-- | Prepending values to existing JSON association values.+module Text.JSON.JSONPrepend+(+  JSONPrepend(..)+) where++import Data.ByteString+import qualified Data.Trie as T+import Text.JSONb+import qualified Text.JSON as J+import Text.JSON.Types++-- | Prepending values to existing JSON association values.+class JSONPrepend j s | j -> s where+  -- | Prepends the given association if the JSON is an object.+  (->:) ::+    (s, j) -- ^ The value to prepend if the JSON value is an object.+    -> j -- ^ The JSON value to prepend to.+    -> j+  -- | Prepends the given value if the JSON is an array.+  (-->>:) ::+    j -- ^ The value to prepend if the JSON value is an array..+    -> j -- ^ The JSON value to prepend to.+    -> j++instance JSONPrepend JSON ByteString where+  (k, v) ->: Object x = Object (T.insert k v x)+  _      ->: x        = x+  k -->>: Array x = Array (k : x)+  _ -->>: x       = x++instance JSONPrepend J.JSValue [Char] where+  k ->: (J.JSObject (JSONObject x)) = (J.JSObject (JSONObject (k:x)))+  _ ->: x        = x+  k -->>: J.JSArray x = J.JSArray (k : x)+  _ -->>: x       = x
+ Text/JSON/JSONPrint.hs view
@@ -0,0 +1,28 @@+{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FunctionalDependencies #-}++-- | Pretty-printing JSON values.+module Text.JSON.JSONPrint+(+  JSONPrint(..)+) where++import Data.ByteString+import Text.JSONb+import qualified Text.JSON as J+import Text.JSON.Pretty++-- | Pretty-printing JSON values.+class JSONPrint j s | j -> s where+  -- | Print the given JSON value to a pretty-printed value.+  printJSON ::+    j -- ^ The JSON value.+    -> s -- ^ The pretty-printed result.++instance JSONPrint JSON ByteString where+  printJSON =+    encode Compact++instance JSONPrint J.JSValue [Char] where+  printJSON =+    render . pp_value+
− Text/JSONb/Combinator.hs
@@ -1,639 +0,0 @@--- | Combinators for Text.JSONb data types. <http://hackage.haskell.org/package/JSONb>-module Text.JSONb.Combinator where---import Data.Maybe-import Control.Arrow-import Text.JSONb-import Data.ByteString-import qualified Data.ByteString as S-import Data.Trie-import qualified Data.Trie as T-import qualified Data.Foldable as F---- | The type of JSON arrays.-type JArray = [JSON]---- | The type of JSON objects.-type JObject = Trie JSON---- | Inverts the JSON value if it is a boolean.-jNot ::-  JSON-  -> JSON-jNot (Boolean x) = Boolean (not x)-jNot j           = j---- | Runs the given function if the JSON value is a number.-withNumber ::-  (Rational -> Rational)-  -> JSON-  -> JSON-withNumber f (Number r) = Number (f r)-withNumber _ j          = j---- | Runs the given function if the JSON value is a string.-withString ::-  (ByteString -> ByteString)-  -> JSON-  -> JSON-withString f (String x) = String (f x)-withString _ j          = j---- | Runs the given function if the JSON value is an array.-withArray ::-  (JArray -> JArray)-  -> JSON-  -> JSON-withArray f (Array x) = Array (f x)-withArray _ j          = j---- | Runs the given function if the JSON value is an object.-withObject ::-  (JObject -> JObject)-  -> JSON-  -> JSON-withObject f (Object x) = Object (f x)-withObject _ j          = j---- | Runs the given function on the fields if the JSON value is an object.-withObjectFields ::-  (ByteString -> ByteString)-  -> JSON-  -> JSON-withObjectFields f =-  withObject (fromList . fmap (first f) . toList)---- | Runs the given function on the field values if the JSON value is an object.-withObjectValues ::-  (JSON -> JSON)-  -> JSON-  -> JSON-withObjectValues f =-  withObject (fromList . fmap (second f) . toList)---- | Prepends the given association if the JSON is an object.-(->:) ::-  (ByteString, JSON)-  -> JSON-  -> JSON-(k, v) ->: Object x = Object (insert k v x)-_      ->: x        = x---- | Prepends the given value if the JSON is an array.-(-->>:) ::-  JSON-  -> JSON-  -> JSON-k -->>: Array x = Array (k : x)-_ -->>: x       = x---- | A JSON number with the value zero.-jZero ::-  JSON-jZero =-  Number 0---- | A JSON string with a value of empty.-jEmptyString ::-  JSON-jEmptyString =-  String S.empty---- | A JSON array with a value of empty.-jEmptyArray ::-  JSON-jEmptyArray =-  Array []---- | A JSON object with a value of empty.-jEmptyObject ::-  JSON-jEmptyObject =-  Object T.empty---- | A JSON boolean with a value of true.-jTrue ::-  JSON-jTrue =-  Boolean True---- | A JSON boolean with a value of false.-jFalse ::-  JSON-jFalse =-  Boolean False---- | Returns a JSON array value with the given single value.-jSingleArray ::-  JSON-  -> JSON-jSingleArray x =-  Array [x]---- | Returns a JSON object value with the given single association value.-jSingleObject ::-  ByteString-  -> JSON-  -> JSON-jSingleObject k v =-  Object (T.singleton k v)---- | Returns the potential boolean value of a JSON value.-getBool ::-  JSON-  -> Maybe Bool-getBool (Boolean x) = Just x-getBool _           = Nothing---- | Returns the potential number value of a JSON value.-getNumber ::-  JSON-  -> Maybe Rational-getNumber (Number x) = Just x-getNumber _          = Nothing---- | Returns the potential string value of a JSON value.-getString ::-  JSON-  -> Maybe ByteString-getString (String x) = Just x-getString _          = Nothing---- | Returns the potential array value of a JSON value.-getArray ::-  JSON-  -> Maybe [JSON]-getArray (Array x) = Just x-getArray _         = Nothing---- | Returns the potential object value of a JSON value.-getObject ::-  JSON-  -> Maybe (Trie JSON)-getObject (Object x) = Just x-getObject _          = Nothing---- | Returns the potential object fields of a JSON value.-getObjectFields ::-  JSON-  -> Maybe [ByteString]-getObjectFields =-  fmap keys . getObject---- | Returns the potential object field values of a JSON value.-getObjectValues ::-  JSON-  -> Maybe [JSON]-getObjectValues =-  fmap (fmap snd . toList) . getObject---- | Returns whether or not a JSON is a boolean value.-isBool ::-  JSON-  -> Bool-isBool =-  isJust . getBool---- | Returns whether or not a JSON is a boolean with the value true.-isTrue ::-  JSON-  -> Bool-isTrue =-  F.or . getBool---- | Returns whether or not a JSON is a boolean with the value false.-isFalse ::-  JSON-  -> Bool-isFalse =-  not . F.and . getBool---- | Returns whether or not a JSON is a number value.-isNumber ::-  JSON-  -> Bool-isNumber =-  isJust . getNumber---- | Returns whether or not a JSON is a string value.-isString ::-  JSON-  -> Bool-isString =-  isJust . getString---- | Returns whether or not a JSON is an array value.-isArray ::-  JSON-  -> Bool-isArray =-  isJust . getArray---- | Returns whether or not a JSON is an object value.-isObject ::-  JSON-  -> Bool-isObject =-  isJust . getObject---- | Returns a number value from a JSON value or if it is not a number, returns the given default.-numberOr ::-  Rational-  -> JSON-  -> Rational-numberOr x =-  fromMaybe x . getNumber---- | Returns a string value from a JSON value or if it is not a string, returns the given default.-stringOr ::-  ByteString-  -> JSON-  -> ByteString-stringOr x =-  fromMaybe x . getString---- | Returns a rational value from a JSON value or if it is not a rational, returns the given default.-arrayOr ::-  JArray-  -> JSON-  -> JArray-arrayOr x =-  fromMaybe x . getArray---- | Returns an object value from a JSON value or if it is not an object, returns the given default.-objectOr ::-  Trie JSON-  -> JSON-  -> Trie JSON-objectOr x =-  fromMaybe x . getObject---- | Returns an object's fields from a JSON value or if it is not an object, returns the given default.-objectFieldsOr ::-  [ByteString]-  -> JSON-  -> [ByteString]-objectFieldsOr x =-  fromMaybe x . getObjectFields---- | Returns an object's values from a JSON value or if it is not an object, returns the given default.-objectValuesOr ::-  [JSON]-  -> JSON-  -> [JSON]-objectValuesOr x =-  fromMaybe x . getObjectValues---- | Returns a number value from a JSON value or if it is not a number, returns zero.-numberOrZero ::-  JSON-  -> Rational-numberOrZero =-  numberOr 0---- | Returns a string value from a JSON value or if it is not a string, returns an empty string.-stringOrEmpty ::-  JSON-  -> ByteString-stringOrEmpty =-  stringOr S.empty---- | Returns an array value from a JSON value or if it is not an array, returns an empty array.-arrayOrEmpty ::-  JSON-  -> JArray-arrayOrEmpty =-  arrayOr []---- | Returns an object value from a JSON value or if it is not an object, returns an empty object.-objectOrEmpty ::-  JSON-  -> Trie JSON-objectOrEmpty =-  objectOr T.empty---- | Returns an object's fields from a JSON value or if it is not an object, returns no fields.-objectFieldsOrEmpty ::-  JSON-  -> [ByteString]-objectFieldsOrEmpty =-  objectFieldsOr []---- | Returns an object's values from a JSON value or if it is not an object, returns no values.-objectValuesOrEmpty ::-  JSON-  -> [JSON]-objectValuesOrEmpty =-  objectValuesOr []---- | Runs a function on the number of a JSON value or if it is not a number, returns the given default.-usingNumber ::-  a-  -> (Rational -> a)-  -> JSON-  -> a-usingNumber a f =-  maybe a f . getNumber---- | Runs a function on the string of a JSON value or if it is not a string, returns the given default.-usingString ::-  a-  -> (ByteString -> a)-  -> JSON-  -> a-usingString a f =-  maybe a f . getString---- | Runs a function on the array of a JSON value or if it is not an array, returns the given default.-usingArray ::-  a-  -> ([JSON] -> a)-  -> JSON-  -> a-usingArray a f =-  maybe a f . getArray---- | Runs a function on the object of a JSON value or if it is not an object, returns the given default.-usingObject ::-  a-  -> (Trie JSON -> a)-  -> JSON-  -> a-usingObject a f =-  maybe a f . getObject---- | Runs a function on the fields of an object of a JSON value or if it is not an object, returns the given default.-usingObjectFields ::-  a-  -> ([ByteString] -> a)-  -> JSON-  -> a-usingObjectFields a f =-  maybe a f . getObjectFields---- | Runs a function on the values of an object of a JSON value or if it is not an object, returns the given default.-usingObjectValues ::-  a-  -> ([JSON] -> a)-  -> JSON-  -> a-usingObjectValues a f =-  maybe a f . getObjectValues---- | Whether or not a JSON value is an object with the given field.-hasField ::-  ByteString-  -> JSON-  -> Bool-hasField s =-  isJust . field s---- | Whether or not a JSON value is an object with the given field. An alias for 'hasField'.-(-?) ::-  ByteString-  -> JSON-  -> Bool-(-?) =-  hasField---- | Returns the possible value associated with the given field if this is an object.-field ::-  ByteString-  -> JSON-  -> Maybe JSON-field s j =-  getObject j >>= T.lookup s---- | Returns the possible value associated with the given field if this is an object. An alias for 'field'.-(-|) ::-  ByteString-  -> JSON-  -> Maybe JSON-(-|) =-  field---- | Returns the value associated with the given field or if this is not an object or has no associated value, return the given default.-fieldOr ::-  ByteString-  -> JSON-  -> JSON-  -> JSON-fieldOr s =-  flip fromMaybe . field s---- | Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON null.-fieldOrNull ::-  ByteString-  -> JSON-  -> JSON-fieldOrNull s j =-  fieldOr s j Null---- | Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON true.-fieldOrTrue ::-  ByteString-  -> JSON-  -> JSON-fieldOrTrue s j =-  fieldOr s j jTrue---- | Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON false.-fieldOrFalse ::-  ByteString-  -> JSON-  -> JSON-fieldOrFalse s j =-  fieldOr s j jFalse---- | Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON zero.-fieldOrZero ::-  ByteString-  -> JSON-  -> JSON-fieldOrZero s j =-  fieldOr s j jZero---- | Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON string that is empty.-fieldOrEmptyString ::-  ByteString-  -> JSON-  -> JSON-fieldOrEmptyString s j =-  fieldOr s j jEmptyString---- | Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON array that is empty.-fieldOrEmptyArray ::-  ByteString-  -> JSON-  -> JSON-fieldOrEmptyArray s j =-  fieldOr s j jEmptyArray---- | Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON object that is empty.-fieldOrEmptyObject ::-  ByteString-  -> JSON-  -> JSON-fieldOrEmptyObject s j =-  fieldOr s j jEmptyObject---- | Traverses down JSON objects with the association fields and returns true if the association graph exists.-hasField' ::-  F.Foldable t =>-  t ByteString-  -> JSON-  -> Bool-hasField' s =-  isJust . field' s---- | Traverses down JSON objects with the association fields and returns true if the association graph exists. An alias for 'hasField''.-(-??) ::-  F.Foldable t =>-  t ByteString-  -> JSON-  -> Bool-(-??) =-  hasField'---- | Traverses down JSON objects with the association fields and returns the potential value.-field' ::-  F.Foldable t =>-  t ByteString-  -> JSON-  -> Maybe JSON-field' =-  flip (F.foldrM field)---- | Traverses down JSON objects with the association fields and returns the potential value. An alias for 'field''.-(-||) ::-  F.Foldable t =>-  t ByteString-  -> JSON-  -> Maybe JSON-(-||) =-  field'---- | Traverses down JSON objects with the association fields and returns the potential value or the given default.-field'Or ::-  F.Foldable t =>-  JSON-  -> t ByteString-  -> JSON-  -> JSON-field'Or d s =-  fromMaybe d . field' s---- | Traverses down JSON objects with the association fields and returns the potential value or a JSON null.-field'OrNull ::-  F.Foldable t =>-  t ByteString-  -> JSON-  -> JSON-field'OrNull =-  field'Or Null---- | Traverses down JSON objects with the association fields and returns the potential value or a JSON true.-field'OrTrue ::-  F.Foldable t =>-  t ByteString-  -> JSON-  -> JSON-field'OrTrue =-  field'Or jTrue---- | Traverses down JSON objects with the association fields and returns the potential value or a JSON false.-field'OrFalse ::-  F.Foldable t =>-  t ByteString-  -> JSON-  -> JSON-field'OrFalse =-  field'Or jFalse---- | Traverses down JSON objects with the association fields and returns the potential value or a JSON zero.-field'OrZero ::-  F.Foldable t =>-  t ByteString-  -> JSON-  -> JSON-field'OrZero =-  field'Or jZero---- | Traverses down JSON objects with the association fields and returns the potential value or a JSON empty string.-field'OrEmptyString ::-  F.Foldable t =>-  t ByteString-  -> JSON-  -> JSON-field'OrEmptyString =-  field'Or jEmptyString---- | Traverses down JSON objects with the association fields and returns the potential value or a JSON empty array.-field'OrEmptyArray ::-  F.Foldable t =>-  t ByteString-  -> JSON-  -> JSON-field'OrEmptyArray =-  field'Or jEmptyArray---- | Traverses down JSON objects with the association fields and returns the potential value or a JSON empty object.-field'OrEmptyObject ::-  F.Foldable t =>-  t ByteString-  -> JSON-  -> JSON-field'OrEmptyObject =-  field'Or jEmptyObject---- | Interacts by parsing the standard input for JSON, passing the result to the given function, then printing the result to standard output.-interactJSON ::-  (Either String JSON -> JSON)-  -> IO ()-interactJSON f =-  S.interact (encode Compact . f . decode)---- | Interacts by parsing the standard input for JSON, passing a failed result with a string error message to the given function, or a successful result to the given function, then printing the result to standard output.-interactJSON' ::-  (String -> JSON)-  -> (JSON -> JSON)-  -> IO ()-interactJSON' l = interactJSON . either l---- | Interacts by parsing the standard input for JSON, executing the given function for a failed result with a string error message, or printing a successful result to the given function and passing the result to standard output.-withJSON ::-  (String -> IO ())-  -> (JSON -> JSON)-  -> IO ()-withJSON f g =-  S.getContents >>= either f (S.putStr . encode Compact . g) . decode---- | Interacts by parsing the given file for JSON, passing the result to the given function, then writing the result to the given file.-interactJSONFile ::-  (Either String JSON -> JSON)-  -> FilePath-  -> FilePath-  -> IO ()-interactJSONFile f i o =-  S.readFile i >>= S.writeFile o . (encode Compact . f) . decode---- | Interacts by parsing the given file for JSON, passing a failed result with a string error message to the given function, or a successful result to the given function, then writing the result to the given file.-interactJSONFile' ::-  (String -> JSON)-  -> (JSON -> JSON)-  -> FilePath-  -> FilePath-  -> IO ()-interactJSONFile' l =-  interactJSONFile . either l---- | Interacts by parsing the given file for JSON, executing the given function for a failed result with a string error message, or printing a successful result to the given function and writing the result to the given file.-withJSONFile ::-  (String -> IO ())-  -> (JSON -> JSON)-  -> FilePath-  -> FilePath-  -> IO ()-withJSONFile f g i o =-  S.readFile i >>= either f (S.writeFile o . encode Compact . g) . decode