ghcjs-base-0.2.0.0: base library for GHCJS

Safe HaskellNone
LanguageHaskell98

JavaScript.JSON.Types.Internal

Contents

Synopsis

Core JSON types

newtype SomeValue m Source

Constructors

SomeValue JSVal 

Instances

Lookup Int Value Source 
Lookup JSString Value Source 
NFData (SomeValue s m) Source 
(~) (MutabilityType *) m (Immutable *) => ResponseType (SomeValue * m) Source 

type Value = SomeValue Immutable Source

data SomeValue' m Source

Constructors

Object !(SomeObject m) 
Array !(SomeJSArray m) 
String !JSString 
Number !Double 
Bool !Bool 
Null 

type Value' = SomeValue' Immutable Source

type Object = SomeObject Immutable Source

type MutableObject = SomeObject Mutable Source

objectPropertiesIO :: SomeObject o -> IO JSArray Source

objectAssocsIO :: SomeObject m -> IO [(JSString, Value)] Source

class Lookup k a where Source

Methods

(!) Source

Arguments

:: k 
-> a 
-> Value

throws when result is not a JSON value

lookup Source

Arguments

:: k 
-> a 
-> Maybe Value

returns Nothing when result is not a JSON value fixme more optimized matching lookup' :: k -> a -> Maybe Value' -- ^ returns Nothing when result is not a JSON value

class IOLookup k a where Source

Methods

(^!) Source

Arguments

:: k 
-> a 
-> IO MutableValue

throws when result is not a JSON value

lookupIO Source

Arguments

:: k 
-> a 
-> IO (Maybe MutableValue)

returns Nothing when result is not a JSON value

lookupIO' Source

Arguments

:: k 
-> a 
-> IO (Maybe MutableValue')

returns Nothing when result is not a JSON value

Type conversion

data Result a :: * -> *

The result of running a Parser.

Constructors

Error String 
Success a 

parse :: (a -> Parser b) -> a -> Result b

Run a Parser.

parseEither :: (a -> Parser b) -> a -> Either String b

Run a Parser with an Either result type. If the parse fails, the Left payload will contain an error message.

parseMaybe :: (a -> Parser b) -> a -> Maybe b

Run a Parser with a Maybe result type.

modifyFailure :: (String -> String) -> Parser a -> Parser a

If the inner Parser failed, modify the failure message using the provided function. This allows you to create more descriptive error messages. For example:

parseJSON (Object o) = modifyFailure
    ("Parsing of the Foo value failed: " ++)
    (Foo <$> o .: "someField")

Since 0.6.2.0

Constructors and accessors

Generic and TH encoding configuration

data Options :: *

Options that specify how to encode/decode your datatype to/from JSON.

Constructors

Options 

Fields

fieldLabelModifier :: String -> String

Function applied to field labels. Handy for removing common record prefixes for example.

constructorTagModifier :: String -> String

Function applied to constructor tags which could be handy for lower-casing them for example.

allNullaryToStringTag :: Bool

If True the constructors of a datatype, with all nullary constructors, will be encoded to just a string with the constructor tag. If False the encoding will always follow the sumEncoding.

omitNothingFields :: Bool

If True record fields with a Nothing value will be omitted from the resulting object. If False the resulting object will include those fields mapping to null.

sumEncoding :: SumEncoding

Specifies how to encode constructors of a sum datatype.

unwrapUnaryRecords :: Bool

Hide the field name when a record constructor has only one field, like a newtype.

Instances

data SumEncoding :: *

Specifies how to encode constructors of a sum datatype.

Constructors

TaggedObject

A constructor will be encoded to an object with a field tagFieldName which specifies the constructor tag (modified by the constructorTagModifier). If the constructor is a record the encoded record fields will be unpacked into this object. So make sure that your record doesn't have a field with the same label as the tagFieldName. Otherwise the tag gets overwritten by the encoded value of that field! If the constructor is not a record the encoded constructor contents will be stored under the contentsFieldName field.

ObjectWithSingleField

A constructor will be encoded to an object with a single field named after the constructor tag (modified by the constructorTagModifier) which maps to the encoded contents of the constructor.

TwoElemArray

A constructor will be encoded to a 2-element array where the first element is the tag of the constructor (modified by the constructorTagModifier) and the second element the encoded contents of the constructor.

defaultTaggedObject :: SumEncoding

Default TaggedObject SumEncoding options:

defaultTaggedObject = TaggedObject
                      { tagFieldName      = "tag"
                      , contentsFieldName = "contents"
                      }

Used for changing CamelCase names into something else.

camelTo :: Char -> String -> String

Converts from CamelCase to another lower case, interspersing the character between all capital letters and their previous entries, except those capital letters that appear together, like API.

For use by Aeson template haskell calls.

camelTo '_' 'CamelCaseAPI' == "camel_case_api"

Other types

newtype DotNetTime :: *

A newtype wrapper for UTCTime that uses the same non-standard serialization format as Microsoft .NET, whose System.DateTime type is by default serialized to JSON as in the following example:

/Date(1302547608878)/

The number represents milliseconds since the Unix epoch.

Constructors

DotNetTime 

Fields

fromDotNetTime :: UTCTime

Acquire the underlying value.