JSON-Combinator 0.2.2 → 0.2.3
raw patch · 8 files changed
+139/−56 lines, 8 filesdep +containersdep +hjsondep +parsecPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: containers, hjson, parsec
API changes (from Hackage documentation)
- Text.JSON.JSONLike: instance JSONLike JSON ByteString [] Trie ByteString
- Text.JSON.JSONLike: instance JSONLike JSValue [Char] [] JSObject [Char]
+ Text.JSON.JSONField: instance JSONField Json [Char]
+ Text.JSON.JSONLike: StringMap :: Map String a -> StringMap a
+ Text.JSON.JSONLike: instance Data a => Data (StringMap a)
+ Text.JSON.JSONLike: instance Eq a => Eq (StringMap a)
+ Text.JSON.JSONLike: instance Foldable StringMap
+ Text.JSON.JSONLike: instance Functor StringMap
+ Text.JSON.JSONLike: instance JSONLike JSON ByteString [] Trie
+ Text.JSON.JSONLike: instance JSONLike JSValue [Char] [] JSObject
+ Text.JSON.JSONLike: instance JSONLike Json [Char] [] StringMap
+ Text.JSON.JSONLike: instance Monoid (StringMap a)
+ Text.JSON.JSONLike: instance Read a => Read (StringMap a)
+ Text.JSON.JSONLike: instance Show a => Show (StringMap a)
+ Text.JSON.JSONLike: instance Traversable StringMap
+ Text.JSON.JSONLike: instance Typeable1 StringMap
+ Text.JSON.JSONLike: newtype StringMap a
+ Text.JSON.JSONLike: runStringMap :: StringMap a -> Map String a
+ Text.JSON.JSONParse: instance JSONParse Json [Char] ParseError
+ Text.JSON.JSONPrepend: instance JSONPrepend Json [Char]
+ Text.JSON.JSONPrint: instance JSONPrint Json [Char]
- Text.JSON.Combinator: arrayOr :: JSONLike j s a o f => a j -> j -> a j
+ Text.JSON.Combinator: arrayOr :: JSONLike j s a o => a j -> j -> a j
- Text.JSON.Combinator: arrayOrEmpty :: (JSONLike j s a o f, Monoid (a j)) => j -> a j
+ Text.JSON.Combinator: arrayOrEmpty :: (JSONLike j s a o, Monoid (a j)) => j -> a 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'OrEmptyArray :: (JSONLike j s a o, 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'OrEmptyObject :: (JSONLike j s a o, 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'OrEmptyString :: (JSONLike j s a o, 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'OrFalse :: (JSONLike j s a o, 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'OrNull :: (JSONLike j s a o, 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'OrTrue :: (JSONLike j s a o, 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: field'OrZero :: (JSONLike j s a o, JSONField j f, Foldable t) => t f -> j -> j
- Text.JSON.Combinator: fieldOrEmptyArray :: (JSONLike j s a o f, JSONField j f, Monoid (a j)) => f -> j -> j
+ Text.JSON.Combinator: fieldOrEmptyArray :: (JSONLike j s a o, 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: fieldOrEmptyObject :: (JSONLike j s a o, 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: fieldOrEmptyString :: (JSONLike j s a o, 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: fieldOrFalse :: (JSONLike j s a o, 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: fieldOrNull :: (JSONLike j s a o, 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: fieldOrTrue :: (JSONLike j s a o, 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: fieldOrZero :: (JSONLike j s a o, JSONField j f) => f -> j -> j
- Text.JSON.Combinator: getArray :: (Failure (ExpectedArray j) m, JSONLike j s a o f) => j -> m (a j)
+ Text.JSON.Combinator: getArray :: (Failure (ExpectedArray j) m, JSONLike j s a o) => j -> m (a j)
- Text.JSON.Combinator: getBool :: (Failure (ExpectedBool j) m, JSONLike j s a o f) => j -> m Bool
+ Text.JSON.Combinator: getBool :: (Failure (ExpectedBool j) m, JSONLike j s a o) => j -> m Bool
- Text.JSON.Combinator: getNumber :: (Failure (ExpectedNumber j) m, JSONLike j s a o f) => j -> m Rational
+ Text.JSON.Combinator: getNumber :: (Failure (ExpectedNumber j) m, JSONLike j s a o) => j -> m Rational
- Text.JSON.Combinator: getObject :: (Failure (ExpectedObject j) m, JSONLike j s a o f) => j -> m (o j)
+ Text.JSON.Combinator: getObject :: (Failure (ExpectedObject j) m, JSONLike j s a o) => j -> m (o j)
- Text.JSON.Combinator: getString :: (Failure (ExpectedString j) m, JSONLike j s a o f) => j -> m s
+ Text.JSON.Combinator: getString :: (Failure (ExpectedString j) m, JSONLike j s a o) => j -> m s
- Text.JSON.Combinator: isArray :: JSONLike j s a o f => j -> Bool
+ Text.JSON.Combinator: isArray :: JSONLike j s a o => j -> Bool
- Text.JSON.Combinator: isBool :: JSONLike j s a o f => j -> Bool
+ Text.JSON.Combinator: isBool :: JSONLike j s a o => j -> Bool
- Text.JSON.Combinator: isFalse :: JSONLike j s a o f => j -> Bool
+ Text.JSON.Combinator: isFalse :: JSONLike j s a o => j -> Bool
- Text.JSON.Combinator: isNumber :: JSONLike j s a o f => j -> Bool
+ Text.JSON.Combinator: isNumber :: JSONLike j s a o => j -> Bool
- Text.JSON.Combinator: isObject :: JSONLike j s a o f => j -> Bool
+ Text.JSON.Combinator: isObject :: JSONLike j s a o => j -> Bool
- Text.JSON.Combinator: isString :: JSONLike j s a o f => j -> Bool
+ Text.JSON.Combinator: isString :: JSONLike j s a o => j -> Bool
- Text.JSON.Combinator: isTrue :: JSONLike j s a o f => j -> Bool
+ Text.JSON.Combinator: isTrue :: JSONLike j s a o => j -> Bool
- Text.JSON.Combinator: jemptyarray :: (Monoid (a j), JSONLike j s a o f) => j
+ Text.JSON.Combinator: jemptyarray :: (Monoid (a j), JSONLike j s a o) => j
- Text.JSON.Combinator: jemptyobject :: (Monoid (o j), JSONLike j s a o f) => j
+ Text.JSON.Combinator: jemptyobject :: (Monoid (o j), JSONLike j s a o) => j
- Text.JSON.Combinator: jemptystring :: (Monoid s, JSONLike j s a o f) => j
+ Text.JSON.Combinator: jemptystring :: (Monoid s, JSONLike j s a o) => j
- Text.JSON.Combinator: jnot :: JSONLike j s a o f => j -> j
+ Text.JSON.Combinator: jnot :: JSONLike j s a o => j -> j
- Text.JSON.Combinator: jsinglearray :: (Applicative a, JSONLike j s a o f) => j -> j
+ Text.JSON.Combinator: jsinglearray :: (Applicative a, JSONLike j s a o) => j -> j
- Text.JSON.Combinator: jsingleobject :: (Applicative o, JSONLike j s a o f) => j -> j
+ Text.JSON.Combinator: jsingleobject :: (Applicative o, JSONLike j s a o) => j -> j
- Text.JSON.Combinator: jzero :: JSONLike j s a o f => j
+ Text.JSON.Combinator: jzero :: JSONLike j s a o => j
- Text.JSON.Combinator: numberOr :: JSONLike j s a o f => Rational -> j -> Rational
+ Text.JSON.Combinator: numberOr :: JSONLike j s a o => Rational -> j -> Rational
- Text.JSON.Combinator: numberOrZero :: JSONLike j s a o f => j -> Rational
+ Text.JSON.Combinator: numberOrZero :: JSONLike j s a o => j -> Rational
- Text.JSON.Combinator: objectOr :: JSONLike j s a o f => o j -> j -> o j
+ Text.JSON.Combinator: objectOr :: JSONLike j s a o => o j -> j -> o j
- Text.JSON.Combinator: objectOrEmpty :: (JSONLike j s a o f, Monoid (o j)) => j -> o j
+ Text.JSON.Combinator: objectOrEmpty :: (JSONLike j s a o, Monoid (o j)) => j -> o j
- Text.JSON.Combinator: stringOr :: JSONLike j s a o f => s -> j -> s
+ Text.JSON.Combinator: stringOr :: JSONLike j s a o => s -> j -> s
- Text.JSON.Combinator: stringOrEmpty :: (JSONLike j s a o f, Monoid s) => j -> s
+ Text.JSON.Combinator: stringOrEmpty :: (JSONLike j s a o, Monoid s) => j -> s
- Text.JSON.Combinator: usingArray :: JSONLike j s a o f => x -> (a j -> x) -> j -> x
+ Text.JSON.Combinator: usingArray :: JSONLike j s a o => x -> (a j -> x) -> j -> x
- Text.JSON.Combinator: usingNumber :: JSONLike j s a o f => x -> (Rational -> x) -> j -> x
+ Text.JSON.Combinator: usingNumber :: JSONLike j s a o => x -> (Rational -> x) -> j -> x
- Text.JSON.Combinator: usingObject :: JSONLike j s a o f => x -> (o j -> x) -> j -> x
+ Text.JSON.Combinator: usingObject :: JSONLike j s a o => x -> (o j -> x) -> j -> x
- Text.JSON.Combinator: usingString :: JSONLike j s a o f => x -> (s -> x) -> j -> x
+ Text.JSON.Combinator: usingString :: JSONLike j s a o => x -> (s -> x) -> j -> x
- Text.JSON.Combinator: withArray :: JSONLike j s a o f => (a j -> a j) -> j -> j
+ Text.JSON.Combinator: withArray :: JSONLike j s a o => (a j -> a j) -> j -> j
- Text.JSON.Combinator: withNumber :: JSONLike j s a o f => (Rational -> Rational) -> j -> j
+ Text.JSON.Combinator: withNumber :: JSONLike j s a o => (Rational -> Rational) -> j -> j
- Text.JSON.Combinator: withObject :: JSONLike j s a o f => (o j -> o j) -> j -> j
+ Text.JSON.Combinator: withObject :: JSONLike j s a o => (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: withObjectFields :: (Functor o, JSONLike j s a o) => (j -> j) -> j -> j
- Text.JSON.Combinator: withString :: JSONLike j s a o f => (s -> s) -> j -> j
+ Text.JSON.Combinator: withString :: JSONLike j s a o => (s -> s) -> j -> j
- Text.JSON.JSONLike: class JSONLike j s a o f | j -> s, j -> a, j -> o, o -> f
+ Text.JSON.JSONLike: class JSONLike j s a o | j -> s, j -> a, j -> o
- 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: foldJSON :: JSONLike j s a o => x -> x -> x -> (Rational -> x) -> (s -> x) -> (a j -> x) -> (o j -> x) -> j -> x
- Text.JSON.JSONLike: jarray :: JSONLike j s a o f => a j -> j
+ Text.JSON.JSONLike: jarray :: JSONLike j s a o => a j -> j
- Text.JSON.JSONLike: jfalse :: JSONLike j s a o f => j
+ Text.JSON.JSONLike: jfalse :: JSONLike j s a o => j
- Text.JSON.JSONLike: jnull :: JSONLike j s a o f => j
+ Text.JSON.JSONLike: jnull :: JSONLike j s a o => j
- Text.JSON.JSONLike: jnumber :: JSONLike j s a o f => Rational -> j
+ Text.JSON.JSONLike: jnumber :: JSONLike j s a o => Rational -> j
- Text.JSON.JSONLike: jobject :: JSONLike j s a o f => o j -> j
+ Text.JSON.JSONLike: jobject :: JSONLike j s a o => o j -> j
- Text.JSON.JSONLike: jstring :: JSONLike j s a o f => s -> j
+ Text.JSON.JSONLike: jstring :: JSONLike j s a o => s -> j
- Text.JSON.JSONLike: jtrue :: JSONLike j s a o f => j
+ Text.JSON.JSONLike: jtrue :: JSONLike j s a o => j
Files
- JSON-Combinator.cabal +4/−1
- Text/JSON/Combinator.hs +50/−50
- Text/JSON/Failure.hs +1/−0
- Text/JSON/JSONField.hs +19/−0
- Text/JSON/JSONLike.hs +45/−5
- Text/JSON/JSONParse.hs +7/−0
- Text/JSON/JSONPrepend.hs +8/−0
- Text/JSON/JSONPrint.hs +5/−0
JSON-Combinator.cabal view
@@ -1,5 +1,5 @@ Name: JSON-Combinator-Version: 0.2.2+Version: 0.2.3 License: BSD3 License-File: LICENSE Author: Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ>@@ -26,6 +26,9 @@ base < 5 && >= 4 , JSONb , json+ , hjson+ , containers+ , parsec , bytestring , bytestring-trie , failure
Text/JSON/Combinator.hs view
@@ -110,7 +110,7 @@ -- | Returns whether or not a JSON is a boolean with the value true. isTrue ::- JSONLike j s a o f =>+ JSONLike j s a o => j -- ^ The JSON value. -> Bool isTrue =@@ -118,7 +118,7 @@ -- | Returns whether or not a JSON is a boolean with the value false. isFalse ::- JSONLike j s a o f =>+ JSONLike j s a o => j -- ^ The JSON value. -> Bool isFalse =@@ -126,7 +126,7 @@ -- | Returns whether or not a JSON is a boolean value. isBool ::- JSONLike j s a o f =>+ JSONLike j s a o => j -- ^ The JSON value. -> Bool isBool =@@ -134,7 +134,7 @@ -- | Returns whether or not a JSON is a number value. isNumber ::- JSONLike j s a o f =>+ JSONLike j s a o => j -- ^ The JSON value. -> Bool isNumber =@@ -142,7 +142,7 @@ -- | Returns whether or not a JSON is a string value. isString ::- JSONLike j s a o f =>+ JSONLike j s a o => j -- ^ The JSON value. -> Bool isString =@@ -150,7 +150,7 @@ -- | Returns whether or not a JSON is an array value. isArray ::- JSONLike j s a o f =>+ JSONLike j s a o => j -- ^ The JSON value. -> Bool isArray =@@ -158,7 +158,7 @@ -- | Returns whether or not a JSON is an object value. isObject ::- JSONLike j s a o f =>+ JSONLike j s a o => j -- ^ The JSON value. -> Bool isObject =@@ -166,7 +166,7 @@ -- | Inverts the JSON value if it is a boolean. jnot ::- JSONLike j s a o f =>+ JSONLike j s a o => j -- ^ The JSON value. -> j jnot j =@@ -181,7 +181,7 @@ -- | Runs the given function if the JSON value is a number. withNumber ::- JSONLike j s a o f =>+ JSONLike j s a o => (Rational -> Rational) -> j -- ^ The JSON value. -> j@@ -190,7 +190,7 @@ -- | Runs the given function if the JSON value is a string. withString ::- JSONLike j s a o f =>+ JSONLike j s a o => (s -> s) -> j -- ^ The JSON value. -> j@@ -199,7 +199,7 @@ -- | Runs the given function if the JSON value is an array. withArray ::- JSONLike j s a o f =>+ JSONLike j s a o => (a j -> a j) -> j -- ^ The JSON value. -> j@@ -208,7 +208,7 @@ -- | Runs the given function if the JSON value is an object. withObject ::- JSONLike j s a o f =>+ JSONLike j s a o => (o j -> o j) -> j -- ^ The JSON value. -> j@@ -217,7 +217,7 @@ -- | Runs the given function on the fields if the JSON value is an object. withObjectFields ::- (Functor o, JSONLike j s a o f) =>+ (Functor o, JSONLike j s a o) => (j -> j) -> j -- ^ The JSON value. -> j@@ -226,7 +226,7 @@ -- | Returns the potential boolean value of a JSON value. getBool ::- (Failure (ExpectedBool j) m, JSONLike j s a o f) =>+ (Failure (ExpectedBool j) m, JSONLike j s a o) => j -- ^ The JSON value. -> m Bool getBool j =@@ -234,7 +234,7 @@ in foldJSON fl (return True) (return False) (const fl) (const fl) (const fl) (const fl) j getNumber ::- (Failure (ExpectedNumber j) m, JSONLike j s a o f) =>+ (Failure (ExpectedNumber j) m, JSONLike j s a o) => j -- ^ The JSON value. -> m Rational getNumber j =@@ -243,7 +243,7 @@ -- | Returns the potential string value of a JSON value. getString ::- (Failure (ExpectedString j) m, JSONLike j s a o f) =>+ (Failure (ExpectedString j) m, JSONLike j s a o) => j -- ^ The JSON value. -> m s getString j =@@ -252,7 +252,7 @@ -- | Returns the potential array value of a JSON value. getArray ::- (Failure (ExpectedArray j) m, JSONLike j s a o f) =>+ (Failure (ExpectedArray j) m, JSONLike j s a o) => j -- ^ The JSON value. -> m (a j) getArray j =@@ -261,7 +261,7 @@ -- | Returns the potential object value of a JSON value. getObject ::- (Failure (ExpectedObject j) m, JSONLike j s a o f) =>+ (Failure (ExpectedObject j) m, JSONLike j s a o) => j -- ^ The JSON value. -> m (o j) getObject j =@@ -270,7 +270,7 @@ -- | 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 =>+ JSONLike j s a o => Rational -> j -- ^ The JSON value. -> Rational@@ -279,7 +279,7 @@ -- | 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 =>+ JSONLike j s a o => s -> j -- ^ The JSON value. -> s@@ -288,7 +288,7 @@ -- | 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 =>+ JSONLike j s a o => a j -> j -- ^ The JSON value. -> a j@@ -297,7 +297,7 @@ -- | 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 =>+ JSONLike j s a o => o j -> j -- ^ The JSON value. -> o j@@ -324,7 +324,7 @@ -- | 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 =>+ JSONLike j s a o => x -> (Rational -> x) -> j -- ^ The JSON value.@@ -334,7 +334,7 @@ -- | 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 =>+ JSONLike j s a o => x -> (s -> x) -> j -- ^ The JSON value.@@ -344,7 +344,7 @@ -- | 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 =>+ JSONLike j s a o => x -> (a j -> x) -> j -- ^ The JSON value.@@ -354,7 +354,7 @@ -- | 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 =>+ JSONLike j s a o => x -> (o j -> x) -> j -- ^ The JSON value.@@ -384,35 +384,35 @@ -- | The JSON value zero. jzero ::- JSONLike j s a o f =>+ JSONLike j s a o => j jzero = jnumber 0 -- | The JSON value empty string. jemptystring ::- (Monoid s, JSONLike j s a o f) =>+ (Monoid s, JSONLike j s a o) => j jemptystring = jstring mempty -- | The JSON value empty array. jemptyarray ::- (Monoid (a j), JSONLike j s a o f) =>+ (Monoid (a j), JSONLike j s a o) => j jemptyarray = jarray mempty -- | The JSON value empty object. jemptyobject ::- (Monoid (o j), JSONLike j s a o f) =>+ (Monoid (o j), JSONLike j s a o) => j jemptyobject = jobject mempty -- | Puts a single value into a JSON array. jsinglearray ::- (Applicative a, JSONLike j s a o f) =>+ (Applicative a, JSONLike j s a o) => j -> j jsinglearray =@@ -420,7 +420,7 @@ -- | Puts a single value into a JSON object. jsingleobject ::- (Applicative o, JSONLike j s a o f) =>+ (Applicative o, JSONLike j s a o) => j -> j jsingleobject =@@ -437,7 +437,7 @@ -- | Returns a number value from a JSON value or if it is not a number, returns zero. numberOrZero ::- JSONLike j s a o f =>+ JSONLike j s a o => j -- ^ The JSON value. -> Rational numberOrZero =@@ -445,7 +445,7 @@ -- | 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) =>+ (JSONLike j s a o, Monoid s) => j -- ^ The JSON value. -> s stringOrEmpty =@@ -453,7 +453,7 @@ -- | 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)) =>+ (JSONLike j s a o, Monoid (a j)) => j -- ^ The JSON value. -> a j arrayOrEmpty =@@ -461,7 +461,7 @@ -- | 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)) =>+ (JSONLike j s a o, Monoid (o j)) => j -- ^ The JSON value. -> o j objectOrEmpty =@@ -513,7 +513,7 @@ -- | 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) =>+ (JSONLike j s a o, JSONField j f) => f -> j -- ^ The JSON value. -> j@@ -522,7 +522,7 @@ -- | 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) =>+ (JSONLike j s a o, JSONField j f) => f -> j -- ^ The JSON value. -> j@@ -531,7 +531,7 @@ -- | 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) =>+ (JSONLike j s a o, JSONField j f) => f -> j -- ^ The JSON value. -> j@@ -540,7 +540,7 @@ -- | 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) =>+ (JSONLike j s a o, JSONField j f) => f -> j -- ^ The JSON value. -> j@@ -549,7 +549,7 @@ -- | 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) =>+ (JSONLike j s a o, JSONField j f, Monoid s) => f -> j -- ^ The JSON value. -> j@@ -558,7 +558,7 @@ -- | 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)) =>+ (JSONLike j s a o, JSONField j f, Monoid (a j)) => f -> j -- ^ The JSON value. -> j@@ -567,7 +567,7 @@ -- | 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)) =>+ (JSONLike j s a o, JSONField j f, Monoid (o j)) => f -> j -- ^ The JSON value. -> j@@ -622,7 +622,7 @@ -- | 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) =>+ (JSONLike j s a o, JSONField j f, F.Foldable t) => t f -> j -- ^ The JSON value. -> j@@ -631,7 +631,7 @@ -- | 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) =>+ (JSONLike j s a o, JSONField j f, F.Foldable t) => t f -> j -- ^ The JSON value. -> j@@ -640,7 +640,7 @@ -- | 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) =>+ (JSONLike j s a o, JSONField j f, F.Foldable t) => t f -> j -- ^ The JSON value. -> j@@ -649,7 +649,7 @@ -- | 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) =>+ (JSONLike j s a o, JSONField j f, F.Foldable t) => t f -> j -- ^ The JSON value. -> j@@ -658,7 +658,7 @@ -- | 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) =>+ (JSONLike j s a o, JSONField j f, F.Foldable t, Monoid s) => t f -> j -- ^ The JSON value. -> j@@ -667,7 +667,7 @@ -- | 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)) =>+ (JSONLike j s a o, JSONField j f, F.Foldable t, Monoid (a j)) => t f -> j -- ^ The JSON value. -> j@@ -676,7 +676,7 @@ -- | 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)) =>+ (JSONLike j s a o, JSONField j f, F.Foldable t, Monoid (o j)) => t f -> j -- ^ The JSON value. -> j
Text/JSON/Failure.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE DeriveDataTypeable #-} +-- | Data structures that used to denote failure of accessing JSON values. module Text.JSON.Failure ( NoSuchField(..)
Text/JSON/JSONField.hs view
@@ -10,9 +10,11 @@ import qualified Data.Trie as T import Text.JSONb import qualified Text.JSON as J+import qualified Text.HJson as H import Text.JSON.Types import Text.JSON.Failure import Control.Failure+import qualified Data.Map as M class JSONField j f | j -> f where field ::@@ -61,3 +63,20 @@ return (fmap snd o) values j = failure (ExpectedObject j)++instance JSONField H.Json [Char] where+ field f (H.JObject o) =+ case M.lookup f o of+ Nothing -> failure (NoSuchField f)+ Just x -> return x+ field f _ =+ failure (NoSuchField f)+ fields (H.JObject o) =+ return (M.keys o)+ fields j =+ failure (ExpectedObject j)+ values (H.JObject o) =+ return (fmap snd (M.toList o))+ values j =+ failure (ExpectedObject j)+
Text/JSON/JSONLike.hs view
@@ -1,19 +1,26 @@-{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FunctionalDependencies #-}+{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FunctionalDependencies, GeneralizedNewtypeDeriving, DeriveDataTypeable #-} -- | The generalisation of a JSON object. module Text.JSON.JSONLike ( JSONLike(..)+, StringMap(..) ) where import Data.ByteString import qualified Data.Trie as T import Text.JSONb import qualified Text.JSON as J+import qualified Text.HJson as H import Text.JSON.Types+import qualified Data.Map as M+import Data.Foldable+import Data.Traversable+import Data.Monoid+import Data.Data -- | The generalisation of a JSON object.-class JSONLike j s a o f | j -> s, j -> a, j -> o, o -> f where+class JSONLike j s a o | j -> s, j -> a, j -> o where -- | Deconstructs a JSON object. foldJSON :: x -- ^ If a JSON null value.@@ -51,7 +58,7 @@ o j -> j -instance JSONLike JSON ByteString [] T.Trie ByteString where+instance JSONLike JSON ByteString [] T.Trie where foldJSON n _ _ _ _ _ _ Null = n foldJSON _ t f _ _ _ _ (Boolean b) =@@ -79,7 +86,7 @@ jobject = Object -instance JSONLike J.JSValue [Char] [] J.JSObject [Char] where+instance JSONLike J.JSValue [Char] [] J.JSObject where foldJSON n _ _ _ _ _ _ J.JSNull = n foldJSON _ t f _ _ _ _ (J.JSBool b) =@@ -107,7 +114,40 @@ jobject = J.JSObject --- orphan instance+newtype StringMap a =+ StringMap {+ runStringMap :: M.Map String a+ } deriving (Eq, Show, Read, Functor, Foldable, Traversable, Monoid, Data, Typeable)++instance JSONLike H.Json [Char] [] StringMap where+ foldJSON n _ _ _ _ _ _ H.JNull =+ n+ foldJSON _ t f _ _ _ _ (H.JBool b) =+ if b then t else f+ foldJSON _ _ _ r _ _ _ (H.JNumber r') =+ r r'+ foldJSON _ _ _ _ s _ _ (H.JString s') =+ s s'+ foldJSON _ _ _ _ _ a _ (H.JArray a') =+ a a'+ foldJSON _ _ _ _ _ _ o (H.JObject o') =+ o (StringMap o')+ jnull =+ H.JNull+ jtrue =+ H.JBool True+ jfalse =+ H.JBool False+ jnumber =+ H.JNumber+ jstring =+ H.JString+ jarray =+ H.JArray+ jobject =+ H.JObject . runStringMap++-- orphan instance, boooo instance Functor J.JSObject where fmap f = J.toJSObject . fmap (fmap f) . J.fromJSObject
Text/JSON/JSONParse.hs view
@@ -10,7 +10,10 @@ import Data.ByteString import Text.JSONb import qualified Text.JSON as J+import qualified Text.HJson as H import Text.JSON.Parsec+import qualified Text.Parsec.Prim as P+import qualified Text.Parsec.Error as E -- | Parsing JSON object values. class JSONParse j p e | j -> p, j -> e where@@ -27,6 +30,10 @@ instance JSONParse J.JSValue [Char] ParseError where parseJSON = parse p_jvalue++instance JSONParse H.Json [Char] E.ParseError where+ parseJSON =+ P.runP H.jsonParser [] -- | Parse a value with an empty source name. parseJSON' ::
Text/JSON/JSONPrepend.hs view
@@ -10,7 +10,9 @@ import qualified Data.Trie as T import Text.JSONb import qualified Text.JSON as J+import qualified Text.HJson as H import Text.JSON.Types+import qualified Data.Map as M -- | Prepending values to existing JSON association values. class JSONPrepend j s | j -> s where@@ -36,3 +38,9 @@ _ ->: x = x k -->>: J.JSArray x = J.JSArray (k : x) _ -->>: x = x++instance JSONPrepend H.Json [Char] where+ (k, v) ->: H.JObject x = H.JObject (M.insert k v x)+ _ ->: x = x+ k -->>: H.JArray x = H.JArray (k : x)+ _ -->>: x = x
Text/JSON/JSONPrint.hs view
@@ -9,7 +9,9 @@ import Data.ByteString import Text.JSONb import qualified Text.JSON as J+import qualified Text.HJson as H import Text.JSON.Pretty+import Text.HJson.Pretty -- | Pretty-printing JSON values. class JSONPrint j s | j -> s where@@ -26,3 +28,6 @@ printJSON = render . pp_value +instance JSONPrint H.Json [Char] where+ printJSON =+ toString " "