Module

JSON

Package
purescript-json
Repository
purescript/purescript-json

#parse Source

parse :: String -> Either String JSON

Attempts to parse a string as a JSON value. If parsing fails, an error message detailing the cause may be returned in the Left of the result.

#null Source

null :: JSON

The JSON null value.

#fromBoolean Source

fromBoolean :: Boolean -> JSON

Converts a Boolean into JSON.

#fromNumber Source

fromNumber :: Number -> JSON

Converts a Number into JSON.

The PureScript Number type admits infinities and a NaN value which are not allowed in JSON, so when encountered, this function will treat those values as 0.

#fromNumberWithDefault Source

fromNumberWithDefault :: Int -> Number -> JSON

Creates a Number into JSON, using a fallback Int value for cases where the PureScript number value is not valid for JSON (NaN, infinity).

#fromInt Source

fromInt :: Int -> JSON

Converts an Int into JSON.

Note: JSON doesn't have a concept of integers. This is provided as a convenience to avoid having to convert Int to Number before creating a JSON value.

#fromString Source

fromString :: String -> JSON

Converts a String into JSON.

Note: this does not parse a string as a JSON value, it takes a PureScript string and produces the corresponding JSON value for that string, similar to the other functions like fromBoolean and fromNumber.

To take a string that contains printed JSON and turn it into a JSON value, see parse.

#fromArray Source

fromArray :: Array JSON -> JSON

Converts an array of JSON values into JSON.

#fromJArray Source

fromJArray :: JArray -> JSON

Converts a JArray into JSON.

#fromJObject Source

fromJObject :: JObject -> JSON

Converts a JObject into JSON.

#case_ Source

case_ :: forall a. (Unit -> a) -> (Boolean -> a) -> (Number -> a) -> (String -> a) -> (JArray -> a) -> (JObject -> a) -> JSON -> a

Performs case analysis on a JSON value.

As the JSON type is not a PureScript sum type, pattern matching cannot be used to discriminate between the potential varieties of value. This function provides an equivalent mechanism by accepting functions that deal with each variety, similar to an exaustive case statement.

The Unit case is for null values.

#toNull Source

toNull :: JSON -> Maybe Unit

Converts a JSON value to Null if the JSON is null.

#toBoolean Source

toBoolean :: JSON -> Maybe Boolean

Converts a JSON value to Boolean if the JSON is a boolean.

#toNumber Source

toNumber :: JSON -> Maybe Number

Converts a JSON value to Number if the JSON is a number.

#toInt Source

toInt :: JSON -> Maybe Int

Converts a JSON Number into an Int.

This is provided for convenience only.

#toString Source

toString :: JSON -> Maybe String

Converts a JSON value to String if the JSON is a string.

#toArray Source

toArray :: JSON -> Maybe (Array JSON)

Converts a JSON value to Array JSON if the JSON is an array.

#toJArray Source

toJArray :: JSON -> Maybe JArray

Converts a JSON value to JArray if the JSON is an array.

#toJObject Source

toJObject :: JSON -> Maybe JObject

Converts a JSON value to Object if the JSON is an object.

#print Source

print :: JSON -> String

Prints a JSON value as a compact (single line) string.

#printIndented Source

printIndented :: JSON -> String

Prints a JSON value as a "pretty" string with newlines and indentation.

Re-exports from JSON.Internal

#JSON Source

data JSON

A type that represents all varieties of JSON value.

This is not a PureScript sum type, instead the underlying JSON representation is used for efficiency and performance reasons.

Instances

#JObject Source

data JObject

A type that represents JSON objects. Similar to the JSON type, this is not a PureScript type, but represents the underlying representation for JSON objects.

Instances

#JArray Source

data JArray

A type that represents JSON arrays. Similar to the JSON type, this is not a PureScript type, but represents the underlying representation for JSON arrays.

Instances