JSON-Combinator-0.2.6: A combinator library on top of a generalised JSON type

Text.JSON.Combinator

Contents

Description

Combinators for JSON data types.

Synopsis

Transformers

jnotSource

Arguments

:: JSONLike j s a o 
=> j

The JSON value.

-> j 

Inverts the JSON value if it is a boolean.

withNumberSource

Arguments

:: JSONLike j s a o 
=> (Rational -> Rational) 
-> j

The JSON value.

-> j 

Runs the given function if the JSON value is a number.

withStringSource

Arguments

:: JSONLike j s a o 
=> (s -> s) 
-> j

The JSON value.

-> j 

Runs the given function if the JSON value is a string.

withArraySource

Arguments

:: JSONLike j s a o 
=> (a j -> a j) 
-> j

The JSON value.

-> j 

Runs the given function if the JSON value is an array.

withObjectSource

Arguments

:: JSONLike j s a o 
=> (o j -> o j) 
-> j

The JSON value.

-> j 

Runs the given function if the JSON value is an object.

withObjectFieldsSource

Arguments

:: (Functor o, JSONLike j s a o) 
=> (j -> j) 
-> j

The JSON value.

-> j 

Runs the given function on the fields if the JSON value is an object.

Constructors

jzero :: JSONLike j s a o => jSource

The JSON value zero.

jemptystring :: (Monoid s, JSONLike j s a o) => jSource

The JSON value empty string.

jemptyarray :: (Monoid (a j), JSONLike j s a o) => jSource

The JSON value empty array.

jemptyobject :: (Monoid (o j), JSONLike j s a o) => jSource

The JSON value empty object.

jsinglearray :: (Applicative a, JSONLike j s a o) => j -> jSource

Puts a single value into a JSON array.

jsingleobject :: (Applicative o, JSONLike j s a o) => j -> jSource

Puts a single value into a JSON object.

Accessors

getBoolSource

Arguments

:: (Failure (ExpectedBool j) m, JSONLike j s a o) 
=> j

The JSON value.

-> m Bool 

Returns the potential boolean value of a JSON value.

getNumberSource

Arguments

:: (Failure (ExpectedNumber j) m, JSONLike j s a o) 
=> j

The JSON value.

-> m Rational 

Returns the potential number value of a JSON value.

getStringSource

Arguments

:: (Failure (ExpectedString j) m, JSONLike j s a o) 
=> j

The JSON value.

-> m s 

Returns the potential string value of a JSON value.

getArraySource

Arguments

:: (Failure (ExpectedArray j) m, JSONLike j s a o) 
=> j

The JSON value.

-> m (a j) 

Returns the potential array value of a JSON value.

getObjectSource

Arguments

:: (Failure (ExpectedObject j) m, JSONLike j s a o) 
=> j

The JSON value.

-> m (o j) 

Returns the potential object value of a JSON value.

Decisions

isBoolSource

Arguments

:: JSONLike j s a o 
=> j

The JSON value.

-> Bool 

Returns whether or not a JSON is a boolean value.

isTrueSource

Arguments

:: JSONLike j s a o 
=> j

The JSON value.

-> Bool 

Returns whether or not a JSON is a boolean with the value true.

isFalseSource

Arguments

:: JSONLike j s a o 
=> j

The JSON value.

-> Bool 

Returns whether or not a JSON is a boolean with the value false.

isNumberSource

Arguments

:: JSONLike j s a o 
=> j

The JSON value.

-> Bool 

Returns whether or not a JSON is a number value.

isStringSource

Arguments

:: JSONLike j s a o 
=> j

The JSON value.

-> Bool 

Returns whether or not a JSON is a string value.

isArraySource

Arguments

:: JSONLike j s a o 
=> j

The JSON value.

-> Bool 

Returns whether or not a JSON is an array value.

isObjectSource

Arguments

:: JSONLike j s a o 
=> j

The JSON value.

-> Bool 

Returns whether or not a JSON is an object value.

Accessors with default

numberOrSource

Arguments

:: JSONLike j s a o 
=> Rational 
-> j

The JSON value.

-> Rational 

Returns a number value from a JSON value or if it is not a number, returns the given default.

stringOrSource

Arguments

:: JSONLike j s a o 
=> s 
-> j

The JSON value.

-> s 

Returns a string value from a JSON value or if it is not a string, returns the given default.

arrayOrSource

Arguments

:: JSONLike j s a o 
=> a j 
-> j

The JSON value.

-> a j 

Returns a rational value from a JSON value or if it is not a rational, returns the given default.

objectOrSource

Arguments

:: JSONLike j s a o 
=> o j 
-> j

The JSON value.

-> o j 

Returns an object value from a JSON value or if it is not an object, returns the given default.

fieldsOrSource

Arguments

:: JSONField j f 
=> [f] 
-> j

The JSON value.

-> [f] 

Returns an object's fields from a JSON value or if it is not an object, returns the given default.

valuesOrSource

Arguments

:: JSONField j f 
=> [j] 
-> j

The JSON value.

-> [j] 

Returns an object's values from a JSON value or if it is not an object, returns the given default.

numberOrZeroSource

Arguments

:: JSONLike j s a o 
=> j

The JSON value.

-> Rational 

Returns a number value from a JSON value or if it is not a number, returns zero.

stringOrEmptySource

Arguments

:: (JSONLike j s a o, Monoid s) 
=> j

The JSON value.

-> s 

Returns a string value from a JSON value or if it is not a string, returns an empty string.

arrayOrEmptySource

Arguments

:: (JSONLike j s a o, Monoid (a j)) 
=> j

The JSON value.

-> a j 

Returns an array value from a JSON value or if it is not an array, returns an empty array.

objectOrEmptySource

Arguments

:: (JSONLike j s a o, Monoid (o j)) 
=> j

The JSON value.

-> o j 

Returns an object value from a JSON value or if it is not an object, returns an empty object.

objectFieldsOrEmptySource

Arguments

:: (JSONField j f, Monoid (o j)) 
=> j

The JSON value.

-> [f] 

Returns an object's fields from a JSON value or if it is not an object, returns no fields.

objectValuesOrEmptySource

Arguments

:: (JSONField j f, Monoid (o j)) 
=> j

The JSON value.

-> [j] 

Returns an object's values from a JSON value or if it is not an object, returns no values.

Combinators

usingNumberSource

Arguments

:: JSONLike j s a o 
=> x 
-> (Rational -> x) 
-> j

The JSON value.

-> x 

Runs a function on the number of a JSON value or if it is not a number, returns the given default.

usingStringSource

Arguments

:: JSONLike j s a o 
=> x 
-> (s -> x) 
-> j

The JSON value.

-> x 

Runs a function on the string of a JSON value or if it is not a string, returns the given default.

usingArraySource

Arguments

:: JSONLike j s a o 
=> x 
-> (a j -> x) 
-> j

The JSON value.

-> x 

Runs a function on the array of a JSON value or if it is not an array, returns the given default.

usingObjectSource

Arguments

:: JSONLike j s a o 
=> x 
-> (o j -> x) 
-> j

The JSON value.

-> x 

Runs a function on the object of a JSON value or if it is not an object, returns the given default.

usingObjectFieldsSource

Arguments

:: JSONField j f 
=> a 
-> ([f] -> a) 
-> j

The JSON value.

-> a 

Runs a function on the fields of an object of a JSON value or if it is not an object, returns the given default.

usingObjectValuesSource

Arguments

:: JSONField j f 
=> a 
-> ([j] -> a) 
-> j

The JSON value.

-> a 

Runs a function on the values of an object of a JSON value or if it is not an object, returns the given default.

Object field accessors

hasFieldSource

Arguments

:: JSONField j f 
=> f 
-> j

The JSON value.

-> Bool 

Whether or not a JSON value is an object with the given field.

(-?)Source

Arguments

:: JSONField j f 
=> f 
-> j

The JSON value.

-> Bool 

Whether or not a JSON value is an object with the given field. An alias for hasField.

(-|)Source

Arguments

:: (JSONField j f, Failure (NoSuchFieldOrExpectedObject f j) m) 
=> f 
-> j

The JSON value.

-> m j 

Returns the possible value associated with the given field if this is an object. An alias for field.

fieldOrSource

Arguments

:: JSONField j f 
=> f 
-> j

The default.

-> j

The JSON value.

-> j 

Returns the value associated with the given field or if this is not an object or has no associated value, return the given default.

fieldOrNullSource

Arguments

:: (JSONLike j s a o, JSONField j f) 
=> f 
-> j

The JSON value.

-> j 

Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON null.

fieldOrTrueSource

Arguments

:: (JSONLike j s a o, JSONField j f) 
=> f 
-> j

The JSON value.

-> j 

Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON true.

fieldOrFalseSource

Arguments

:: (JSONLike j s a o, JSONField j f) 
=> f 
-> j

The JSON value.

-> j 

Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON false.

fieldOrZeroSource

Arguments

:: (JSONLike j s a o, JSONField j f) 
=> f 
-> j

The JSON value.

-> j 

Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON zero.

fieldOrEmptyStringSource

Arguments

:: (JSONLike j s a o, JSONField j f, Monoid s) 
=> f 
-> j

The JSON value.

-> j 

Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON string that is empty.

fieldOrEmptyArraySource

Arguments

:: (JSONLike j s a o, JSONField j f, Monoid (a j)) 
=> f 
-> j

The JSON value.

-> j 

Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON array that is empty.

fieldOrEmptyObjectSource

Arguments

:: (JSONLike j s a o, JSONField j f, Monoid (o j)) 
=> f 
-> j

The JSON value.

-> j 

Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON object that is empty.

hasField'Source

Arguments

:: (JSONField j f, Foldable t) 
=> t f 
-> j

The JSON value.

-> Bool 

Traverses down JSON objects with the association fields and returns true if the association graph exists.

(-??)Source

Arguments

:: (JSONField j f, Foldable t) 
=> t f 
-> j

The JSON value.

-> Bool 

Traverses down JSON objects with the association fields and returns true if the association graph exists. An alias for hasField'.

field' :: (Foldable t, Failure (NoSuchFieldOrExpectedObject f j) m, JSONField j f) => t f -> j -> m jSource

Traverses down JSON objects with the association fields and returns the potential value.

(-||) :: (Foldable t, Failure (NoSuchFieldOrExpectedObject f j) m, JSONField j f) => t f -> j -> m jSource

Traverses down JSON objects with the association fields and returns the potential value. An alias for field'.

field'OrSource

Arguments

:: (JSONField j f, Foldable t) 
=> j

The default.

-> t f 
-> j

The JSON value.

-> j 

Traverses down JSON objects with the association fields and returns the potential value or the given default.

field'OrNullSource

Arguments

:: (JSONLike j s a o, JSONField j f, Foldable t) 
=> t f 
-> j

The JSON value.

-> j 

Traverses down JSON objects with the association fields and returns the potential value or a JSON null.

field'OrTrueSource

Arguments

:: (JSONLike j s a o, JSONField j f, Foldable t) 
=> t f 
-> j

The JSON value.

-> j 

Traverses down JSON objects with the association fields and returns the potential value or a JSON true.

field'OrFalseSource

Arguments

:: (JSONLike j s a o, JSONField j f, Foldable t) 
=> t f 
-> j

The JSON value.

-> j 

Traverses down JSON objects with the association fields and returns the potential value or a JSON false.

field'OrZeroSource

Arguments

:: (JSONLike j s a o, JSONField j f, Foldable t) 
=> t f 
-> j

The JSON value.

-> j 

Traverses down JSON objects with the association fields and returns the potential value or a JSON zero.

field'OrEmptyStringSource

Arguments

:: (JSONLike j s a o, JSONField j f, Foldable t, Monoid s) 
=> t f 
-> j

The JSON value.

-> j 

Traverses down JSON objects with the association fields and returns the potential value or a JSON empty string.

field'OrEmptyArraySource

Arguments

:: (JSONLike j s a o, JSONField j f, Foldable t, Monoid (a j)) 
=> t f 
-> j

The JSON value.

-> j 

Traverses down JSON objects with the association fields and returns the potential value or a JSON empty array.

field'OrEmptyObjectSource

Arguments

:: (JSONLike j s a o, JSONField j f, Foldable t, Monoid (o j)) 
=> t f 
-> j

The JSON value.

-> j 

Traverses down JSON objects with the association fields and returns the potential value or a JSON empty object.

Stdin/stdout interaction

interactJSON :: (JSONPrint j' s, JSONParse j s e, Interact s) => (Either e j -> j') -> IO ()Source

Interacts by parsing the standard input for JSON, passing the result to the given function, then printing the result to standard output.

interactJSON' :: (JSONPrint j' s, JSONParse j s e, Interact s) => (e -> j') -> (j -> j') -> IO ()Source

Interacts by parsing the standard input for JSON, passing a failed result with a string error message to the given function, or a successful result to the given function, then printing the result to standard output.

withJSON :: (Interact p, Interact s, JSONPrint j' s, JSONParse j p e) => (e -> IO ()) -> (j -> j') -> IO ()Source

Interacts by parsing the standard input for JSON, executing the given function for a failed result with a string error message, or printing a successful result to the given function and passing the result to standard output.

File I/O

readJSONFile :: (JSONParse j a e, InteractFile a) => FilePath -> IO (Either e j)Source

Parses a JSON file into a possible JSON object.

writeJSONFile :: (InteractFile b, JSONPrint a b) => FilePath -> a -> IO ()Source

Writes a JSON object to a file.

interactJSONFile :: (InteractFile p, InteractFile s, JSONPrint j' s, JSONParse j p e) => (Either e j -> j') -> FilePath -> FilePath -> IO ()Source

Interacts by parsing the given file for JSON, passing the result to the given function, then writing the result to the given file.

interactJSONFile' :: (InteractFile p, InteractFile s, JSONPrint j' s, JSONParse j p e) => (e -> j') -> (j -> j') -> FilePath -> FilePath -> IO ()Source

Interacts by parsing the given file for JSON, passing a failed result with a string error message to the given function, or a successful result to the given function, then writing the result to the given file.

withJSONFile :: (InteractFile p, InteractFile s, JSONPrint j' s, JSONParse j p e) => (e -> IO ()) -> (j -> j') -> FilePath -> FilePath -> IO ()Source

Interacts by parsing the given file for JSON, executing the given function for a failed result with a string error message, or printing a successful result to the given function and writing the result to the given file.

Modules containing additional combinators