Module

Data.Argonaut.Core

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

This module defines a data type and various functions for creating and manipulating JSON values. The README contains additional documentation for this module.

#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

#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.

#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.

#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.

#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.

#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.

#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.

#isNull Source

isNull :: Json -> Boolean

Check if the provided Json is the null value

#isBoolean Source

isBoolean :: Json -> Boolean

Check if the provided Json is a Boolean

#isNumber Source

isNumber :: Json -> Boolean

Check if the provided Json is a Number

#isString Source

isString :: Json -> Boolean

Check if the provided Json is a String

#isArray Source

isArray :: Json -> Boolean

Check if the provided Json is an Array

#isObject Source

isObject :: Json -> Boolean

Check if the provided Json is an Object

#fromBoolean Source

fromBoolean :: Boolean -> Json

Construct Json from a Boolean value

#fromNumber Source

fromNumber :: Number -> Json

Construct Json from a Number value

#fromString Source

fromString :: String -> Json

Construct Json from a String value. If you would like to parse a string of JSON into valid Json, see jsonParser.

#fromArray Source

fromArray :: Array Json -> Json

Construct Json from an array of Json values

#fromObject Source

fromObject :: Object Json -> Json

Construct Json from an object with Json values

#toNull Source

toNull :: Json -> Maybe Unit

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

#toBoolean Source

toBoolean :: Json -> Maybe Boolean

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

#toNumber Source

toNumber :: Json -> Maybe Number

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

#toString Source

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.

#toArray Source

toArray :: Json -> Maybe (Array Json)

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

#toObject Source

toObject :: Json -> Maybe (Object Json)

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

#jsonNull Source

jsonNull :: Json

The JSON null value represented as Json

#jsonTrue Source

jsonTrue :: Json

The true boolean value represented as Json

#jsonFalse Source

jsonFalse :: Json

The false boolean value represented as Json

#jsonZero Source

jsonZero :: Json

The number zero represented as Json

#jsonEmptyString Source

jsonEmptyString :: Json

An empty string represented as Json

#jsonEmptyArray Source

jsonEmptyArray :: Json

An empty array represented as Json

#jsonSingletonArray Source

jsonSingletonArray :: Json -> Json

Constructs a Json array value containing only the provided value

#jsonEmptyObject Source

jsonEmptyObject :: Json

An empty object represented as Json

#jsonSingletonObject Source

jsonSingletonObject :: String -> Json -> Json

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

#stringify Source

stringify :: Json -> String

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

#stringifyWithIndent Source

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.