Module

Data.Argonaut

Re-exports from Data.Argonaut.Core

#Json

data Json

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

#toString

toString :: Json -> Maybe String

Convert Json to a String value, if the Json is a string. To write a Json value to a JSON string, see stringify.

#toObject

toObject :: Json -> Maybe (Object Json)

Convert Json to an Object of Json values, if the Json is an object.

#toNumber

toNumber :: Json -> Maybe Number

Convert Json to a Number value, if the Json is a number.

#toNull

toNull :: Json -> Maybe Unit

Convert Json to the Unit value if the Json is the null value

#toBoolean

toBoolean :: Json -> Maybe Boolean

Convert Json to a Boolean value, if the Json is a boolean.

#toArray

toArray :: Json -> Maybe (Array Json)

Convert Json to an Array of Json values, if the Json is an array.

#stringifyWithIndent

stringifyWithIndent :: Int -> Json -> String

Converts a Json value to a JSON string. The first Int argument specifies the amount of white space characters to use as indentation. This number is capped at 10 (if it is greater, the value is just 10). Values less than 1 indicate that no space should be used.

#stringify

stringify :: Json -> String

Converts a Json value to a JSON string. To retrieve a string from a Json string value, see fromString.

#jsonZero

jsonZero :: Json

The number zero represented as Json

#jsonTrue

jsonTrue :: Json

The true boolean value represented as Json

#jsonSingletonObject

jsonSingletonObject :: String -> Json -> Json

Constructs a Json object value containing only the provided key and value

#jsonSingletonArray

jsonSingletonArray :: Json -> Json

Constructs a Json array value containing only the provided value

#jsonNull

jsonNull :: Json

The JSON null value represented as Json

#jsonFalse

jsonFalse :: Json

The false boolean value represented as Json

#jsonEmptyString

jsonEmptyString :: Json

An empty string represented as Json

#jsonEmptyObject

jsonEmptyObject :: Json

An empty object represented as Json

#jsonEmptyArray

jsonEmptyArray :: Json

An empty array represented as Json

#isString

isString :: Json -> Boolean

Check if the provided Json is a String

#isObject

isObject :: Json -> Boolean

Check if the provided Json is an Object

#isNumber

isNumber :: Json -> Boolean

Check if the provided Json is a Number

#isNull

isNull :: Json -> Boolean

Check if the provided Json is the null value

#isBoolean

isBoolean :: Json -> Boolean

Check if the provided Json is a Boolean

#isArray

isArray :: Json -> Boolean

Check if the provided Json is an Array

#fromString

fromString :: String -> Json

Construct the Json representation of a String value. Note that this function only produces Json containing a single piece of String data (similar to fromBoolean, fromNumber, etc.). This function does NOT convert the String encoding of a JSON value to Json - For that purpose, you'll need to use jsonParser.

#fromObject

fromObject :: Object Json -> Json

Construct Json from an object with Json values

#fromNumber

fromNumber :: Number -> Json

Construct Json from a Number value

#fromBoolean

fromBoolean :: Boolean -> Json

Construct Json from a Boolean value

#fromArray

fromArray :: Array Json -> Json

Construct Json from an array of Json values

#caseJsonString

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

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

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

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

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

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

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

#printJsonDecodeError

printJsonDecodeError :: JsonDecodeError -> String

Prints a JsonDecodeError as a readable error message.

#parseJson

parseJson :: String -> Either JsonDecodeError Json

Attempt to parse a string as Json, failing with a typed error if the JSON string is malformed.

#getFieldOptional'

getFieldOptional' :: forall a. DecodeJson a => Object Json -> String -> Either JsonDecodeError (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

getFieldOptional :: forall a. DecodeJson a => Object Json -> String -> Either JsonDecodeError (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.

#getField

getField :: forall a. DecodeJson a => Object Json -> String -> Either JsonDecodeError 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.

#defaultField

defaultField :: forall a. Either JsonDecodeError (Maybe a) -> a -> Either JsonDecodeError 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 }

#(.:?)

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

#(.:!)

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

#(.:)

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

#(.!=)

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

Re-exports from Data.Argonaut.Encode

#extendOptional

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

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

#extend

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

The named Encoders of the (~>) operator.

#assocOptional

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

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

#assoc

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

The named Encoders of the (:=) operator.

#(~>?)

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

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

#(~>)

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

Extends a Json object with a Tuple String Json property.

#(:=?)

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.

#(:=)

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

newtype JsonPrim

Constructors

Instances

#runJsonPrim

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

#print

#primToJson

#primStr

#primNum

#primNull

#primBool

#insideOut

#inferEmpty

#downIndex

#downField

#cursorSet

#cursorGet

Re-exports from Data.Argonaut.Parser

#jsonParser

jsonParser :: String -> Either String Json

Parse a JSON string, constructing the Json value described by the string. To convert a string into a Json string, see fromString.

Re-exports from Data.Argonaut.Prisms

Re-exports from Data.Argonaut.Traversals

Modules