lux/data/format/json

Functionality for reading, generating and processing values in the JSON format.

For more information, please see: http://www.json.org/

Types

Array

(type: Array
  (lux/data/struct/vector;Vector JSON))

Boolean

(type: Boolean
  lux;Bool)

Gen

JSON generators.

(type: (Gen a)
  (-> a JSON))

JSON

(type: #rec JSON
  (#Null Null)
  (#Boolean Boolean)
  (#Number Number)
  (#String String)
  (#Array (lux/data/struct/vector;Vector JSON))
  (#Object (lux/data/struct/dict;Dict String JSON)))

Null

(type: Null
  lux;Unit)

Number

(type: Number
  lux;Real)

Object

(type: Object
  (lux/data/struct/dict;Dict String JSON))

Parser

JSON parsers.

(type: (Parser a)
  (-> JSON (lux/data/error;Error a)))

String

(type: String
  lux;Text)

Macros

Codec<JSON,?>

## A macro for automatically producing JSON codecs.
(type: Variant
  (#Case0 Bool)
  (#Case1 Int)
  (#Case2 Real))

(type: Record
  {#unit Unit
   #bool Bool
   #int Int
   #real Real
   #char Char
   #text Text
   #maybe (Maybe Int)
   #list (List Int)
   #variant Variant
   #tuple [Int Real Char]})

(derived: (Codec<JSON,?> Record))

json

## A way to produce JSON literals.
(json true)

(json 123)

(json 456.78)

(json "Some text")

(json #null)

(json ["this" "is" "an" "array"])

(json {"this" "is"
       "an" "object"})

shape

## Builds a parser that ensures the (inclusive) shape of an array or object.
(shape [bool! int! real!])

(shape {"isAlive" bool!
        "age" int!
        "income" real!})

shape!

## Builds a parser that ensures the (exclusive) shape of an array or object.
(shape! [bool! int! real!])

(shape! {"isAlive" bool!
         "age" int!
         "income" real!})

Structs

Applicative<Parser>

(lux/control/applicative;Applicative Parser)

Codec<Text,JSON>

(lux/control/codec;Codec lux;Text JSON)

Eq<JSON>

(lux/control/eq;Eq JSON)

Functor<Parser>

(lux/control/functor;Functor Parser)

Monad<Parser>

(lux/control/monad;Monad Parser)

Values

(alt pa pb json)

Heterogeneous alternative combinator.

(All [a b] (-> (Parser a) (Parser b) (Parser (| a b))))

any

Just returns the JSON input without applying any logic.

(Parser JSON)

(array parser)

Parses a JSON array, assuming that every element can be parsed the same way.

(All [a] (-> (Parser a) (Parser (lux;List a))))

(array-size! size json)

Ensures a JSON array has the specified size.

(-> lux;Nat (Parser lux;Unit))

(at idx parser)

Parses an element inside a JSON array.

(All [a] (-> lux;Nat (Parser a) (Parser a)))

(bool json)

Reads a JSON value as bool.

(Parser lux;Bool)

(bool! test json)

Ensures a JSON value is a boolean.

(-> lux;Bool (Parser lux;Unit))

(bool? test json)

Asks whether a JSON value is a boolean.

(-> lux;Bool (Parser lux;Bool))

(char json)

Reads a JSON value as a single-character string.

(Parser lux;Char)

(char! test json)

Ensures a JSON value is a single-character string with the specified character.

(-> lux;Char (Parser lux;Unit))

(char? test json)

Asks whether a JSON value is a single-character string with the specified character.

(-> lux;Char (Parser lux;Bool))

(either pl pr json)

Homogeneous alternative combinator.

(All [a] (-> (Parser a) (Parser a) (Parser a)))

(ensure test parser json)

Only parses a JSON if it passes a test (which is also a parser).

(All [a] (-> (Parser lux;Unit) (Parser a) (Parser a)))

(field field-name parser)

Parses a field inside a JSON object.

(All [a] (-> lux;Text (Parser a) (Parser a)))

(fields json)

Get all the fields in a JSON object.

(-> JSON (lux/data/error;Error (lux;List String)))

(gen-array value)

A JSON generator for arrays.

(Gen Array)

(gen-boolean value)

A JSON generator for booleans.

(Gen Boolean)

(gen-nullable gen)

Builds a JSON generator for potentially inexistent values.

(All [a] (-> (Gen a) (Gen (lux;Maybe a))))

(gen-number value)

A JSON generator for numbers.

(Gen Number)

(gen-object value)

A JSON generator for objects.

(Gen Object)

(gen-string value)

A JSON generator for strings.

(Gen String)

(get key json)

A JSON object field getter.

(-> String JSON (lux/data/error;Error JSON))

(get-array key json)

A JSON object field getter for arrays.

(-> lux;Text JSON (lux/data/error;Error Array))

(get-boolean key json)

A JSON object field getter for booleans.

(-> lux;Text JSON (lux/data/error;Error Boolean))

(get-number key json)

A JSON object field getter for numbers.

(-> lux;Text JSON (lux/data/error;Error Number))

(get-object key json)

A JSON object field getter for objects.

(-> lux;Text JSON (lux/data/error;Error Object))

(get-string key json)

A JSON object field getter for strings.

(-> lux;Text JSON (lux/data/error;Error String))

(int json)

Reads a JSON value as int.

(Parser lux;Int)

(int! test json)

Ensures a JSON value is a number.

(-> lux;Int (Parser lux;Unit))

(int? test json)

Asks whether a JSON value is a number.

(-> lux;Int (Parser lux;Bool))

null

The null JSON value.

JSON

(nullable parser)

A parser that can handle the presence of null values.

(All [a] (-> (Parser a) (Parser (lux;Maybe a))))

(object parser)

Parses a JSON object, assuming that every field's value can be parsed the same way.

(All [a] (-> (Parser a) (Parser (lux/data/struct/dict;Dict String a))))

(object-fields! wanted-fields json)

Ensures that every field in the list of wanted-fields is present in a JSON object.

(-> (lux;List String) (Parser lux;Unit))

(opt p json)

Optionality combinator.

(All [a] (-> (Parser a) (Parser (lux;Maybe a))))

(real json)

Reads a JSON value as real.

(Parser lux;Real)

(real! test json)

Ensures a JSON value is a number.

(-> lux;Real (Parser lux;Unit))

(real? test json)

Asks whether a JSON value is a number.

(-> lux;Real (Parser lux;Bool))

(run parser json)

(All [a] (-> (Parser a) JSON (lux/data/error;Error a)))

(seq pa pb)

Sequencing combinator.

(All [a b] (-> (Parser a) (Parser b) (Parser [a b])))

(set key value json)

A JSON object field setter.

(-> String JSON JSON (lux/data/error;Error JSON))

(text json)

Reads a JSON value as text.

(Parser lux;Text)

(text! test json)

Ensures a JSON value is a string.

(-> lux;Text (Parser lux;Unit))

(text? test json)

Asks whether a JSON value is a string.

(-> lux;Text (Parser lux;Bool))

(unit json)

Reads a JSON value as unit.

(Parser lux;Unit)