Module JSON.Data

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

Author: Jonas Oberschweiber

Version: February 2025

Summary of exported operations:

fromJObject :: JObject -> [(String,JValue)]  Deterministic 
Extracts the list of name / JSON value pairs from a JSON object.
toJObject :: [(String,JValue)] -> JObject  Deterministic 
Transforms a list of name / JSON value pairs into a JSON object.
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.

Exported datatypes:


JValue

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

Exported operations:

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.