on 6c8754e help sign in
48 lines 1.2 kB history raw
1{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3{-# LANGUAGE ScopedTypeVariables #-}
5-- |
6-- Module : Network.Google.Data.JSON
7-- Copyright : (c) 2015 Brendan Hay <brendan.g.hay@gmail.com>
8-- License : Mozilla Public License, v. 2.0.
9-- Maintainer : Brendan Hay <brendan.g.hay@gmail.com>
10-- Stability : provisional
11-- Portability : non-portable (GHC extensions)
12--
13module Network.Google.Data.JSON
14 ( JSONValue
15 , parseJSONObject
16 , parseJSONText
17 , toJSONText
19 -- * Re-exports
20 , FromJSON (..)
21 , ToJSON (..)
23 , withObject
24 , emptyObject
25 , object
27 , (.=)
28 , (.:)
29 , (.:?)
30 , (.!=)
31 ) where
33import Data.Aeson
34import Data.Aeson.Types
35import Data.HashMap.Strict (HashMap)
36import Data.Text (Text)
37import Servant.API
39type JSONValue = Value
41parseJSONObject :: FromJSON a => HashMap Text Value -> Parser a
42parseJSONObject = parseJSON . Object
44parseJSONText :: FromText a => String -> Value -> Parser a
45parseJSONText n = withText n (maybe (fail n) pure . fromText)
47toJSONText :: ToText a => a -> Value
48toJSONText = String . toText