Module

Data.Argonaut

Package
purescript-argonaut
Repository
purescript-contrib/purescript-argonaut

Re-exports from Data.Argonaut.Core

#Json Source

data Json :: Type

The type of JSON data. The underlying representation is the same as what would be returned from JavaScript's JSON.parse function; that is, ordinary JavaScript booleans, strings, arrays, objects, etc.

Instances

#stringify Source

#jsonZero Source

#jsonTrue Source

#jsonSingletonObject Source

#jsonSingletonArray Source

#jsonNull Source

#jsonFalse Source

#jsonEmptyString Source

#jsonEmptyObject Source

#jsonEmptyArray Source

#isBoolean Source

#fromString Source

#fromNumber Source

#fromBoolean Source

#caseJsonString Source

caseJsonString :: forall a. a -> (String -> a) -> Json -> a

A simpler version of caseJson which accepts a callback for when the Json argument was a String, and a default value for all other cases.

#caseJsonObject Source

caseJsonObject :: forall a. a -> (Object Json -> a) -> Json -> a

A simpler version of caseJson which accepts a callback for when the Json argument was an Object, and a default value for all other cases.

#caseJsonNumber Source

caseJsonNumber :: forall a. a -> (Number -> a) -> Json -> a

A simpler version of caseJson which accepts a callback for when the Json argument was a Number, and a default value for all other cases.

#caseJsonNull Source

caseJsonNull :: forall a. a -> (Unit -> a) -> Json -> a

A simpler version of caseJson which accepts a callback for when the Json argument was null, and a default value for all other cases.

#caseJsonBoolean Source

caseJsonBoolean :: forall a. a -> (Boolean -> a) -> Json -> a

A simpler version of caseJson which accepts a callback for when the Json argument was a Boolean, and a default value for all other cases.

#caseJsonArray Source

caseJsonArray :: forall a. a -> (Array Json -> a) -> Json -> a

A simpler version of caseJson which accepts a callback for when the Json argument was a Array Json, and a default value for all other cases.

#caseJson Source

caseJson :: forall a. (Unit -> a) -> (Boolean -> a) -> (Number -> a) -> (String -> a) -> (Array Json -> a) -> (Object Json -> a) -> Json -> a

Case analysis for Json values. See the README for more information.

Re-exports from Data.Argonaut.Decode

#getFieldOptionalDeprecated Source

getFieldOptionalDeprecated :: forall a. Warn (Text "`.??` is deprecated, use `.:!` or `.:?` instead") => DecodeJson a => Object Json -> String -> Either String (Maybe a)

#getFieldOptional' Source

getFieldOptional' :: forall a. DecodeJson a => Object Json -> String -> Either String (Maybe a)

Attempt to get the value for a given key on an Object Json.

The result will be Right Nothing if the key and value are not present, or if the key is present and the value is null.

Use this accessor if the key and value are optional in your object. If the key and value are mandatory, use getField (.:) instead.

#getFieldOptional Source

getFieldOptional :: forall a. DecodeJson a => Object Json -> String -> Either String (Maybe a)

Attempt to get the value for a given key on an Object Json.

The result will be Right Nothing if the key and value are not present, but will fail if the key is present but the value cannot be converted to the right type.

This function will treat null as a value and attempt to decode it into your desired type. If you would like to treat null values the same as absent values, use getFieldOptional (.:?) instead.

#getFieldDeprecated Source

getFieldDeprecated :: forall a. Warn (Text "`.?` is deprecated, use `.:` instead") => DecodeJson a => Object Json -> String -> Either String a

#getField Source

getField :: forall a. DecodeJson a => Object Json -> String -> Either String a

Attempt to get the value for a given key on an Object Json.

Use this accessor if the key and value must be present in your object. If the key and value are optional, use getFieldOptional' (.:?) instead.

#defaultFieldDeprecated Source

defaultFieldDeprecated :: forall a. Warn (Text "`.?=` is deprecated, use `.!=` instead") => Either String (Maybe a) -> a -> Either String a

#defaultField Source

defaultField :: forall a. Either String (Maybe a) -> a -> Either String a

Helper for use in combination with .:? to provide default values for optional Object Json fields.

Example usage:

newtype MyType = MyType
  { foo :: String
  , bar :: Maybe Int
  , baz :: Boolean
  }

instance decodeJsonMyType :: DecodeJson MyType where
  decodeJson json = do
    x <- decodeJson json
    foo <- x .: "foo" -- mandatory field
    bar <- x .:? "bar" -- optional field
    baz <- x .:? "baz" .!= false -- optional field with default value of `false`
    pure $ MyType { foo, bar, baz }

#(.??) Source

Operator alias for Data.Argonaut.Decode.Combinators.getFieldOptionalDeprecated (non-associative / precedence 7)

#(.?=) Source

Operator alias for Data.Argonaut.Decode.Combinators.defaultFieldDeprecated (non-associative / precedence 6)

#(.?) Source

Operator alias for Data.Argonaut.Decode.Combinators.getFieldDeprecated (non-associative / precedence 7)

#(.:?) Source

Operator alias for Data.Argonaut.Decode.Combinators.getFieldOptional' (non-associative / precedence 7)

#(.:!) Source

Operator alias for Data.Argonaut.Decode.Combinators.getFieldOptional (non-associative / precedence 7)

#(.:) Source

Operator alias for Data.Argonaut.Decode.Combinators.getField (non-associative / precedence 7)

#(.!=) Source

Operator alias for Data.Argonaut.Decode.Combinators.defaultField (non-associative / precedence 6)

Re-exports from Data.Argonaut.Encode

#extendOptional Source

extendOptional :: forall a. EncodeJson a => Maybe (Tuple String Json) -> a -> Json

The named implementation of the (~>?) operator.

#extend Source

extend :: forall a. EncodeJson a => Tuple String Json -> a -> Json

The named implementation of the (~>) operator.

#assocOptional Source

assocOptional :: forall a. EncodeJson a => String -> Maybe a -> Maybe (Tuple String Json)

The named implementation of the (:=?) operator.

#assoc Source

assoc :: forall a. EncodeJson a => String -> a -> Tuple String Json

The named implementation of the (:=) operator.

#(~>?) Source

Operator alias for Data.Argonaut.Encode.Combinators.extendOptional (right-associative / precedence 6)

Optionally extends a Json object with an optional Tuple String Json property.

#(~>) Source

Operator alias for Data.Argonaut.Encode.Combinators.extend (right-associative / precedence 6)

Extends a Json object with a Tuple String Json property.

#(:=?) Source

Operator alias for Data.Argonaut.Encode.Combinators.assocOptional (non-associative / precedence 7)

Creates an optional Tuple String Json entry, representing an optional key/value pair for an object.

#(:=) Source

Operator alias for Data.Argonaut.Encode.Combinators.assoc (non-associative / precedence 7)

Creates a Tuple String Json entry, representing a key/value pair for an object.

Re-exports from Data.Argonaut.JCursor

#JsonPrim Source

newtype JsonPrim

Constructors

Instances

#runJsonPrim Source

runJsonPrim :: JsonPrim -> (forall a. (Unit -> a) -> (Boolean -> a) -> (Number -> a) -> (String -> a) -> a)

#inferEmpty Source

#fail Source

fail :: forall b a. Show a => a -> Either String b

#downIndex Source

#cursorSet Source

Re-exports from Data.Argonaut.Parser

Re-exports from Data.Argonaut.Prisms

Re-exports from Data.Argonaut.Traversals

Modules
Data.Argonaut