{-# OPTIONS_GHC -fno-warn-orphans #-}
module Z.Data.JSON
(
JSON(..), Value(..), defaultSettings, Settings(..)
, snakeCase, trainCase
, DecodeError
, decode, decode', decodeText, decodeText'
, ParseChunks, decodeChunk, decodeChunks
, encode, encodeChunks, encodeText
, prettyJSON, prettyValue, prettyJSON', prettyValue'
, parseValue, parseValue'
, gToValue, gFromValue, gEncodeJSON
, convertValue, Converter(..), fail', (<?>), prependContext
, PathElement(..), ConvertError(..)
, typeMismatch, fromNull, withBool, withScientific, withBoundedScientific, withRealFloat
, withBoundedIntegral, withText, withArray, withKeyValues, withFlatMap, withFlatMapR
, withHashMap, withHashMapR, withEmbeddedJSON
, (.:), (.:?), (.:!), convertField, convertFieldMaybe, convertFieldMaybe'
, (.=), object, (.!), object', KVItem
) where
import Data.Char
import Data.Functor.Compose
import Data.Functor.Const
import Data.Functor.Identity
import Data.Functor.Product
import Data.Functor.Sum
import qualified Data.Monoid as Monoid
import Data.Proxy (Proxy (..))
import Data.Scientific (toBoundedInteger)
import qualified Data.Semigroup as Semigroup
import Data.Tagged (Tagged (..))
import Data.Time (Day, DiffTime, LocalTime, NominalDiffTime, TimeOfDay, UTCTime, ZonedTime)
import Data.Time.Calendar (CalendarDiffDays (..), DayOfWeek (..))
import Data.Time.LocalTime (CalendarDiffTime (..))
import Data.Time.Clock.System (SystemTime (..))
import Data.Version (Version(versionBranch), makeVersion)
import Foreign.C.Types
import System.Exit (ExitCode(..))
import qualified Z.Data.Builder as B
import Z.Data.JSON.Base
import qualified Z.Data.Parser as P
import qualified Z.Data.Text as T
import Data.UUID.Types (UUID)
snakeCase :: String -> T.Text
{-# INLINE snakeCase #-}
snakeCase :: String -> Text
snakeCase = Char -> String -> Text
symbCase Char
'_'
trainCase :: String -> T.Text
{-# INLINE trainCase #-}
trainCase :: String -> Text
trainCase = Char -> String -> Text
symbCase Char
'-'
symbCase :: Char -> String -> T.Text
{-# INLINABLE symbCase #-}
symbCase :: Char -> String -> Text
symbCase Char
sym = String -> Text
T.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
go forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a}. (a -> a) -> [a] -> [a]
applyFirst Char -> Char
toLower
where
go :: String -> String
go [] = []
go (Char
x:String
xs) | Char -> Bool
isUpper Char
x = Char
sym forall a. a -> [a] -> [a]
: Char -> Char
toLower Char
x forall a. a -> [a] -> [a]
: String -> String
go String
xs
| Bool
otherwise = Char
x forall a. a -> [a] -> [a]
: String -> String
go String
xs
applyFirst :: (a -> a) -> [a] -> [a]
applyFirst a -> a
_ [] = []
applyFirst a -> a
f (a
x:[a]
xs) = a -> a
f a
xforall a. a -> [a] -> [a]
: [a]
xs
instance JSON ExitCode where
{-# INLINE fromValue #-}
fromValue :: Value -> Converter ExitCode
fromValue (String Text
"ExitSuccess") = forall (m :: * -> *) a. Monad m => a -> m a
return ExitCode
ExitSuccess
fromValue (Number Scientific
x) =
case forall i. (Integral i, Bounded i) => Scientific -> Maybe i
toBoundedInteger Scientific
x of
Just Int
i -> forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> ExitCode
ExitFailure Int
i)
Maybe Int
_ -> forall a. Text -> Converter a
fail' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Builder a -> Text
B.unsafeBuildText forall a b. (a -> b) -> a -> b
$ do
Builder ()
"converting ExitCode failed, value is either floating or will cause over or underflow: "
Scientific -> Builder ()
B.scientific Scientific
x
fromValue Value
_ = forall a. Text -> Converter a
fail' Text
"converting ExitCode failed, expected a string or number"
{-# INLINE toValue #-}
toValue :: ExitCode -> Value
toValue ExitCode
ExitSuccess = Text -> Value
String Text
"ExitSuccess"
toValue (ExitFailure Int
n) = Scientific -> Value
Number (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n)
{-# INLINE encodeJSON #-}
encodeJSON :: ExitCode -> Builder ()
encodeJSON ExitCode
ExitSuccess = Builder ()
"\"ExitSuccess\""
encodeJSON (ExitFailure Int
n) = forall a. (Integral a, Bounded a) => a -> Builder ()
B.int Int
n
instance JSON Version where
{-# INLINE fromValue #-}
fromValue :: Value -> Converter Version
fromValue Value
v = [Int] -> Version
makeVersion forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. JSON a => Value -> Converter a
fromValue Value
v
{-# INLINE toValue #-}
toValue :: Version -> Value
toValue = forall a. JSON a => a -> Value
toValue forall b c a. (b -> c) -> (a -> b) -> a -> c
. Version -> [Int]
versionBranch
{-# INLINE encodeJSON #-}
encodeJSON :: Version -> Builder ()
encodeJSON = forall a. JSON a => a -> Builder ()
encodeJSON forall b c a. (b -> c) -> (a -> b) -> a -> c
. Version -> [Int]
versionBranch
instance JSON UTCTime where
{-# INLINE fromValue #-}
fromValue :: Value -> Converter UTCTime
fromValue = forall a. Text -> (Text -> Converter a) -> Value -> Converter a
withText Text
"UTCTime" forall a b. (a -> b) -> a -> b
$ \ Text
t ->
case forall a. Parser a -> Bytes -> Either ParseError a
P.parse' (Parser UTCTime
P.utcTime forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
P.endOfInput) (Text -> Bytes
T.getUTF8Bytes Text
t) of
Left ParseError
err -> forall a. Text -> Converter a
fail' forall a b. (a -> b) -> a -> b
$ Text
"could not parse date as UTCTime: " forall a. Semigroup a => a -> a -> a
<> forall a. Print a => a -> Text
T.toText ParseError
err
Right UTCTime
r -> forall (m :: * -> *) a. Monad m => a -> m a
return UTCTime
r
{-# INLINE toValue #-}
toValue :: UTCTime -> Value
toValue UTCTime
t = Text -> Value
String (forall a. Builder a -> Text
B.unsafeBuildText (UTCTime -> Builder ()
B.utcTime UTCTime
t))
{-# INLINE encodeJSON #-}
encodeJSON :: UTCTime -> Builder ()
encodeJSON = Builder () -> Builder ()
B.quotes forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTCTime -> Builder ()
B.utcTime
instance JSON ZonedTime where
{-# INLINE fromValue #-}
fromValue :: Value -> Converter ZonedTime
fromValue = forall a. Text -> (Text -> Converter a) -> Value -> Converter a
withText Text
"ZonedTime" forall a b. (a -> b) -> a -> b
$ \ Text
t ->
case forall a. Parser a -> Bytes -> Either ParseError a
P.parse' (Parser ZonedTime
P.zonedTime forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
P.endOfInput) (Text -> Bytes
T.getUTF8Bytes Text
t) of
Left ParseError
err -> forall a. Text -> Converter a
fail' forall a b. (a -> b) -> a -> b
$ Text
"could not parse date as ZonedTime: " forall a. Semigroup a => a -> a -> a
<> forall a. Print a => a -> Text
T.toText ParseError
err
Right ZonedTime
r -> forall (m :: * -> *) a. Monad m => a -> m a
return ZonedTime
r
{-# INLINE toValue #-}
toValue :: ZonedTime -> Value
toValue ZonedTime
t = Text -> Value
String (forall a. Builder a -> Text
B.unsafeBuildText (ZonedTime -> Builder ()
B.zonedTime ZonedTime
t))
{-# INLINE encodeJSON #-}
encodeJSON :: ZonedTime -> Builder ()
encodeJSON = Builder () -> Builder ()
B.quotes forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZonedTime -> Builder ()
B.zonedTime
instance JSON Day where
{-# INLINE fromValue #-}
fromValue :: Value -> Converter Day
fromValue = forall a. Text -> (Text -> Converter a) -> Value -> Converter a
withText Text
"Day" forall a b. (a -> b) -> a -> b
$ \ Text
t ->
case forall a. Parser a -> Bytes -> Either ParseError a
P.parse' (Parser Day
P.day forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
P.endOfInput) (Text -> Bytes
T.getUTF8Bytes Text
t) of
Left ParseError
err -> forall a. Text -> Converter a
fail' forall a b. (a -> b) -> a -> b
$ Text
"could not parse date as Day: " forall a. Semigroup a => a -> a -> a
<> forall a. Print a => a -> Text
T.toText ParseError
err
Right Day
r -> forall (m :: * -> *) a. Monad m => a -> m a
return Day
r
{-# INLINE toValue #-}
toValue :: Day -> Value
toValue Day
t = Text -> Value
String (forall a. Builder a -> Text
B.unsafeBuildText (Day -> Builder ()
B.day Day
t))
{-# INLINE encodeJSON #-}
encodeJSON :: Day -> Builder ()
encodeJSON = Builder () -> Builder ()
B.quotes forall b c a. (b -> c) -> (a -> b) -> a -> c
. Day -> Builder ()
B.day
instance JSON LocalTime where
{-# INLINE fromValue #-}
fromValue :: Value -> Converter LocalTime
fromValue = forall a. Text -> (Text -> Converter a) -> Value -> Converter a
withText Text
"LocalTime" forall a b. (a -> b) -> a -> b
$ \ Text
t ->
case forall a. Parser a -> Bytes -> Either ParseError a
P.parse' (Parser LocalTime
P.localTime forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
P.endOfInput) (Text -> Bytes
T.getUTF8Bytes Text
t) of
Left ParseError
err -> forall a. Text -> Converter a
fail' forall a b. (a -> b) -> a -> b
$ Text
"could not parse date as LocalTime: " forall a. Semigroup a => a -> a -> a
<> forall a. Print a => a -> Text
T.toText ParseError
err
Right LocalTime
r -> forall (m :: * -> *) a. Monad m => a -> m a
return LocalTime
r
{-# INLINE toValue #-}
toValue :: LocalTime -> Value
toValue LocalTime
t = Text -> Value
String (forall a. Builder a -> Text
B.unsafeBuildText (LocalTime -> Builder ()
B.localTime LocalTime
t))
{-# INLINE encodeJSON #-}
encodeJSON :: LocalTime -> Builder ()
encodeJSON = Builder () -> Builder ()
B.quotes forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocalTime -> Builder ()
B.localTime
instance JSON TimeOfDay where
{-# INLINE fromValue #-}
fromValue :: Value -> Converter TimeOfDay
fromValue = forall a. Text -> (Text -> Converter a) -> Value -> Converter a
withText Text
"TimeOfDay" forall a b. (a -> b) -> a -> b
$ \ Text
t ->
case forall a. Parser a -> Bytes -> Either ParseError a
P.parse' (Parser TimeOfDay
P.timeOfDay forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
P.endOfInput) (Text -> Bytes
T.getUTF8Bytes Text
t) of
Left ParseError
err -> forall a. Text -> Converter a
fail' forall a b. (a -> b) -> a -> b
$ Text
"could not parse time as TimeOfDay: " forall a. Semigroup a => a -> a -> a
<> forall a. Print a => a -> Text
T.toText ParseError
err
Right TimeOfDay
r -> forall (m :: * -> *) a. Monad m => a -> m a
return TimeOfDay
r
{-# INLINE toValue #-}
toValue :: TimeOfDay -> Value
toValue TimeOfDay
t = Text -> Value
String (forall a. Builder a -> Text
B.unsafeBuildText (TimeOfDay -> Builder ()
B.timeOfDay TimeOfDay
t))
{-# INLINE encodeJSON #-}
encodeJSON :: TimeOfDay -> Builder ()
encodeJSON = Builder () -> Builder ()
B.quotes forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeOfDay -> Builder ()
B.timeOfDay
instance JSON NominalDiffTime where
{-# INLINE fromValue #-}
fromValue :: Value -> Converter NominalDiffTime
fromValue = forall a.
Text -> (Scientific -> Converter a) -> Value -> Converter a
withBoundedScientific Text
"NominalDiffTime" forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Real a, Fractional b) => a -> b
realToFrac
{-# INLINE toValue #-}
toValue :: NominalDiffTime -> Value
toValue = Scientific -> Value
Number forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Real a, Fractional b) => a -> b
realToFrac
{-# INLINE encodeJSON #-}
encodeJSON :: NominalDiffTime -> Builder ()
encodeJSON = Scientific -> Builder ()
B.scientific' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Real a, Fractional b) => a -> b
realToFrac
instance JSON DiffTime where
{-# INLINE fromValue #-}
fromValue :: Value -> Converter DiffTime
fromValue = forall a.
Text -> (Scientific -> Converter a) -> Value -> Converter a
withBoundedScientific Text
"DiffTime" forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Real a, Fractional b) => a -> b
realToFrac
{-# INLINE toValue #-}
toValue :: DiffTime -> Value
toValue = Scientific -> Value
Number forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Real a, Fractional b) => a -> b
realToFrac
{-# INLINE encodeJSON #-}
encodeJSON :: DiffTime -> Builder ()
encodeJSON = Scientific -> Builder ()
B.scientific' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Real a, Fractional b) => a -> b
realToFrac
instance JSON SystemTime where
{-# INLINE fromValue #-}
fromValue :: Value -> Converter SystemTime
fromValue = forall a.
Text -> (FlatMap Text Value -> Converter a) -> Value -> Converter a
withFlatMapR Text
"SystemTime" forall a b. (a -> b) -> a -> b
$ \ FlatMap Text Value
v ->
Int64 -> Word32 -> SystemTime
MkSystemTime forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FlatMap Text Value
v forall a. JSON a => FlatMap Text Value -> Text -> Converter a
.: Text
"seconds" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FlatMap Text Value
v forall a. JSON a => FlatMap Text Value -> Text -> Converter a
.: Text
"nanoseconds"
{-# INLINE toValue #-}
toValue :: SystemTime -> Value
toValue (MkSystemTime Int64
s Word32
ns) = [(Text, Value)] -> Value
object [ Text
"seconds" forall v. JSON v => Text -> v -> (Text, Value)
.= Int64
s , Text
"nanoseconds" forall v. JSON v => Text -> v -> (Text, Value)
.= Word32
ns ]
{-# INLINE encodeJSON #-}
encodeJSON :: SystemTime -> Builder ()
encodeJSON (MkSystemTime Int64
s Word32
ns) = KVItem -> Builder ()
object' (Text
"seconds" forall v. JSON v => Text -> v -> KVItem
.! Int64
s forall a. Semigroup a => a -> a -> a
<> Text
"nanoseconds" forall v. JSON v => Text -> v -> KVItem
.! Word32
ns)
instance JSON CalendarDiffTime where
{-# INLINE fromValue #-}
fromValue :: Value -> Converter CalendarDiffTime
fromValue = forall a.
Text -> (FlatMap Text Value -> Converter a) -> Value -> Converter a
withFlatMapR Text
"CalendarDiffTime" forall a b. (a -> b) -> a -> b
$ \ FlatMap Text Value
v ->
Integer -> NominalDiffTime -> CalendarDiffTime
CalendarDiffTime forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FlatMap Text Value
v forall a. JSON a => FlatMap Text Value -> Text -> Converter a
.: Text
"months" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FlatMap Text Value
v forall a. JSON a => FlatMap Text Value -> Text -> Converter a
.: Text
"time"
{-# INLINE toValue #-}
toValue :: CalendarDiffTime -> Value
toValue (CalendarDiffTime Integer
m NominalDiffTime
nt) = [(Text, Value)] -> Value
object [ Text
"months" forall v. JSON v => Text -> v -> (Text, Value)
.= Integer
m , Text
"time" forall v. JSON v => Text -> v -> (Text, Value)
.= NominalDiffTime
nt ]
{-# INLINE encodeJSON #-}
encodeJSON :: CalendarDiffTime -> Builder ()
encodeJSON (CalendarDiffTime Integer
m NominalDiffTime
nt) = KVItem -> Builder ()
object' (Text
"months" forall v. JSON v => Text -> v -> KVItem
.! Integer
m forall a. Semigroup a => a -> a -> a
<> Text
"time" forall v. JSON v => Text -> v -> KVItem
.! NominalDiffTime
nt)
instance JSON CalendarDiffDays where
{-# INLINE fromValue #-}
fromValue :: Value -> Converter CalendarDiffDays
fromValue = forall a.
Text -> (FlatMap Text Value -> Converter a) -> Value -> Converter a
withFlatMapR Text
"CalendarDiffDays" forall a b. (a -> b) -> a -> b
$ \ FlatMap Text Value
v ->
Integer -> Integer -> CalendarDiffDays
CalendarDiffDays forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FlatMap Text Value
v forall a. JSON a => FlatMap Text Value -> Text -> Converter a
.: Text
"months" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FlatMap Text Value
v forall a. JSON a => FlatMap Text Value -> Text -> Converter a
.: Text
"days"
{-# INLINE toValue #-}
toValue :: CalendarDiffDays -> Value
toValue (CalendarDiffDays Integer
m Integer
d) = [(Text, Value)] -> Value
object [Text
"months" forall v. JSON v => Text -> v -> (Text, Value)
.= Integer
m, Text
"days" forall v. JSON v => Text -> v -> (Text, Value)
.= Integer
d]
{-# INLINE encodeJSON #-}
encodeJSON :: CalendarDiffDays -> Builder ()
encodeJSON (CalendarDiffDays Integer
m Integer
d) = KVItem -> Builder ()
object' (Text
"months" forall v. JSON v => Text -> v -> KVItem
.! Integer
m forall a. Semigroup a => a -> a -> a
<> Text
"days" forall v. JSON v => Text -> v -> KVItem
.! Integer
d)
instance JSON DayOfWeek where
{-# INLINE fromValue #-}
fromValue :: Value -> Converter DayOfWeek
fromValue (String Text
"Monday" ) = forall (f :: * -> *) a. Applicative f => a -> f a
pure DayOfWeek
Monday
fromValue (String Text
"Tuesday" ) = forall (f :: * -> *) a. Applicative f => a -> f a
pure DayOfWeek
Tuesday
fromValue (String Text
"Wednesday") = forall (f :: * -> *) a. Applicative f => a -> f a
pure DayOfWeek
Wednesday
fromValue (String Text
"Thursday" ) = forall (f :: * -> *) a. Applicative f => a -> f a
pure DayOfWeek
Thursday
fromValue (String Text
"Friday" ) = forall (f :: * -> *) a. Applicative f => a -> f a
pure DayOfWeek
Friday
fromValue (String Text
"Saturday" ) = forall (f :: * -> *) a. Applicative f => a -> f a
pure DayOfWeek
Saturday
fromValue (String Text
"Sunday" ) = forall (f :: * -> *) a. Applicative f => a -> f a
pure DayOfWeek
Sunday
fromValue (String Text
_ ) = forall a. Text -> Converter a
fail' Text
"converting DayOfWeek failed, value should be one of weekdays"
fromValue Value
v = forall a. Text -> Text -> Value -> Converter a
typeMismatch Text
"DayOfWeek" Text
"String" Value
v
{-# INLINE toValue #-}
toValue :: DayOfWeek -> Value
toValue DayOfWeek
Monday = Text -> Value
String Text
"Monday"
toValue DayOfWeek
Tuesday = Text -> Value
String Text
"Tuesday"
toValue DayOfWeek
Wednesday = Text -> Value
String Text
"Wednesday"
toValue DayOfWeek
Thursday = Text -> Value
String Text
"Thursday"
toValue DayOfWeek
Friday = Text -> Value
String Text
"Friday"
toValue DayOfWeek
Saturday = Text -> Value
String Text
"Saturday"
toValue DayOfWeek
Sunday = Text -> Value
String Text
"Sunday"
{-# INLINE encodeJSON #-}
encodeJSON :: DayOfWeek -> Builder ()
encodeJSON DayOfWeek
Monday = Builder ()
"\"Monday\""
encodeJSON DayOfWeek
Tuesday = Builder ()
"\"Tuesday\""
encodeJSON DayOfWeek
Wednesday = Builder ()
"\"Wednesday\""
encodeJSON DayOfWeek
Thursday = Builder ()
"\"Thursday\""
encodeJSON DayOfWeek
Friday = Builder ()
"\"Friday\""
encodeJSON DayOfWeek
Saturday = Builder ()
"\"Saturday\""
encodeJSON DayOfWeek
Sunday = Builder ()
"\"Sunday\""
instance JSON UUID where
{-# INLINE fromValue #-}
fromValue :: Value -> Converter UUID
fromValue = forall a. Text -> (Text -> Converter a) -> Value -> Converter a
withText Text
"UUID" forall a b. (a -> b) -> a -> b
$ \ Text
t ->
case forall a. Parser a -> Bytes -> Either ParseError a
P.parse' (Parser UUID
P.uuid forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
P.endOfInput) (Text -> Bytes
T.getUTF8Bytes Text
t) of
Left ParseError
err -> forall a. Text -> Converter a
fail' forall a b. (a -> b) -> a -> b
$ Text
"could not parse UUID: " forall a. Semigroup a => a -> a -> a
<> forall a. Print a => a -> Text
T.toText ParseError
err
Right UUID
r -> forall (m :: * -> *) a. Monad m => a -> m a
return UUID
r
{-# INLINE toValue #-}
toValue :: UUID -> Value
toValue = Text -> Value
String forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Builder a -> Text
B.unsafeBuildText forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder () -> Builder ()
B.quotes forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Builder ()
B.uuid
{-# INLINE encodeJSON #-}
encodeJSON :: UUID -> Builder ()
encodeJSON = Builder () -> Builder ()
B.quotes forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Builder ()
B.uuid
deriving newtype instance JSON (f (g a)) => JSON (Compose f g a)
deriving newtype instance JSON a => JSON (Semigroup.Min a)
deriving newtype instance JSON a => JSON (Semigroup.Max a)
deriving newtype instance JSON a => JSON (Semigroup.First a)
deriving newtype instance JSON a => JSON (Semigroup.Last a)
deriving newtype instance JSON a => JSON (Semigroup.WrappedMonoid a)
deriving newtype instance JSON a => JSON (Semigroup.Dual a)
deriving newtype instance JSON a => JSON (Monoid.First a)
deriving newtype instance JSON a => JSON (Monoid.Last a)
deriving newtype instance JSON a => JSON (Identity a)
deriving newtype instance JSON a => JSON (Const a b)
deriving newtype instance JSON b => JSON (Tagged a b)
instance JSON (Proxy a) where
{-# INLINE fromValue #-}; fromValue :: Value -> Converter (Proxy a)
fromValue = forall a. Text -> a -> Value -> Converter a
fromNull Text
"Proxy" forall {k} (t :: k). Proxy t
Proxy;
{-# INLINE toValue #-}; toValue :: Proxy a -> Value
toValue Proxy a
_ = Value
Null;
{-# INLINE encodeJSON #-}; encodeJSON :: Proxy a -> Builder ()
encodeJSON Proxy a
_ = Builder ()
"null";
deriving newtype instance JSON CChar
deriving newtype instance JSON CSChar
deriving newtype instance JSON CUChar
deriving newtype instance JSON CShort
deriving newtype instance JSON CUShort
deriving newtype instance JSON CInt
deriving newtype instance JSON CUInt
deriving newtype instance JSON CLong
deriving newtype instance JSON CULong
deriving newtype instance JSON CPtrdiff
deriving newtype instance JSON CSize
deriving newtype instance JSON CWchar
deriving newtype instance JSON CSigAtomic
deriving newtype instance JSON CLLong
deriving newtype instance JSON CULLong
deriving newtype instance JSON CBool
deriving newtype instance JSON CIntPtr
deriving newtype instance JSON CUIntPtr
deriving newtype instance JSON CIntMax
deriving newtype instance JSON CUIntMax
deriving newtype instance JSON CClock
deriving newtype instance JSON CTime
deriving newtype instance JSON CUSeconds
deriving newtype instance JSON CSUSeconds
deriving newtype instance JSON CFloat
deriving newtype instance JSON CDouble
deriving anyclass instance (JSON (f a), JSON (g a), JSON a) => JSON (Sum f g a)
deriving anyclass instance (JSON a, JSON b) => JSON (Either a b)
deriving anyclass instance (JSON (f a), JSON (g a)) => JSON (Product f g a)
deriving anyclass instance (JSON a, JSON b) => JSON (a, b)
deriving anyclass instance (JSON a, JSON b, JSON c) => JSON (a, b, c)
deriving anyclass instance (JSON a, JSON b, JSON c, JSON d) => JSON (a, b, c, d)
deriving anyclass instance (JSON a, JSON b, JSON c, JSON d, JSON e) => JSON (a, b, c, d, e)
deriving anyclass instance (JSON a, JSON b, JSON c, JSON d, JSON e, JSON f) => JSON (a, b, c, d, e, f)
deriving anyclass instance (JSON a, JSON b, JSON c, JSON d, JSON e, JSON f, JSON g) => JSON (a, b, c, d, e, f, g)