summaryrefslogtreecommitdiffstats
path: root/src/Data/ByteString/Char8/Extended.hs
blob: 8bf76c7b5c095a256898806be87e86386d671d67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{-# LANGUAGE LambdaCase #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Data.ByteString.Char8.Extended
    ( module Data.ByteString.Char8
    , show
    ) where

import Data.Aeson
import Data.Aeson.Types (typeMismatch)
import Data.ByteString.Char8
import Data.Text.Encoding (encodeUtf8)
import Prelude hiding (show)
import qualified Prelude

instance FromJSON ByteString where
  parseJSON = \case
      String t -> pure (encodeUtf8 t)
      invalid -> typeMismatch "ByteString" invalid

instance FromJSONKey ByteString where
  fromJSONKey = FromJSONKeyText encodeUtf8

show :: Show a => a -> ByteString
show = pack . Prelude.show