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
class JSONLike j s a o f | j -> s, j -> a, j -> o, o -> f where
foldJSON ::
x
-> x
-> x
-> (Rational -> x)
-> (s -> x)
-> (a j -> x)
-> (o j -> x)
-> j
-> x
jnull ::
j
jtrue ::
j
jfalse ::
j
jnumber ::
Rational
-> j
jstring ::
s
-> j
jarray ::
a j
-> j
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
instance Functor J.JSObject where
fmap f =
J.toJSObject . fmap (fmap f) . J.fromJSObject