Module JSON.Data

Author
Jonas Oberschweiber
Version
February 2025

This library contains the definition of a data type to represent JSON values.

Exported Datatypes:

Exported Datatypes


data JValue

Abstract representation of a JSON value.

Constructors:

  • JBool :: Bool -> JValue
    a Boolean value (true or false in JSON)
  • JNull :: JValue
    null, i.e. a missing value
  • JString :: String -> JValue
    a JSON string
  • JInt :: Int -> JValue
    a JSON number without decimal point and exponent
  • JNumber :: Float -> JValue
    a JSON number (numbers are always floats in JSON)
  • JArray :: [JValue] -> JValue
    a JSON array, represented by a list of JValues
  • JObject :: JObject -> JValue
    a JSON object, represented by a map from Strings to JValues

Known instances:


newtype JObject

A JSON object is just some representation of a mapping from names (strings) to JSON values. It is an abstract type (rather than an explicit list) to ensure that there are no duplicate entries.

Known instances:


Exported Functions


fromJObject :: JObject -> [(String, JValue)]  Deterministic 

Extracts the list of name / JSON value pairs from a JSON object.

Further infos:
  • solution complete, i.e., able to compute all solutions

toJObject :: [(String, JValue)] -> JObject  Deterministic 

Transforms a list of name / JSON value pairs into a JSON object. Pairs with duplicated names are deleted to ensure that the JSON object is a map from names to values.


lookupName :: String -> JObject -> Maybe JValue  Deterministic 

Retrieves the JSON value with a given name from a JSON object if it exists.


insertField :: String -> JValue -> JObject -> JObject  Deterministic 

Inserts a name / JSON value pair in a JSON object. If the name already exists, the existing value is overwritten.