Combinators for JSON data types.
- jnot :: JSONLike j s a o f => j -> j
- withNumber :: JSONLike j s a o f => (Rational -> Rational) -> j -> j
- withString :: JSONLike j s a o f => (s -> s) -> j -> j
- withArray :: JSONLike j s a o f => (a j -> a j) -> j -> j
- withObject :: JSONLike j s a o f => (o j -> o j) -> j -> j
- withObjectFields :: (Functor o, JSONLike j s a o f) => (j -> j) -> j -> j
- jzero :: JSONLike j s a o f => j
- jemptystring :: (Monoid s, JSONLike j s a o f) => j
- jemptyarray :: (Monoid (a j), JSONLike j s a o f) => j
- jemptyobject :: (Monoid (o j), JSONLike j s a o f) => j
- jsinglearray :: (Applicative a, JSONLike j s a o f) => j -> j
- jsingleobject :: (Applicative o, JSONLike j s a o f) => j -> j
- getBool :: JSONLike j s a o f => j -> Maybe Bool
- getNumber :: JSONLike j s a o f => j -> Maybe Rational
- getString :: JSONLike j s a o f => j -> Maybe s
- getArray :: JSONLike j s a o f => j -> Maybe (a j)
- getObject :: JSONLike j s a o f => j -> Maybe (o j)
- isBool :: JSONLike j s a o f => j -> Bool
- isTrue :: JSONLike j s a o f => j -> Bool
- isFalse :: JSONLike j s a o f => j -> Bool
- isNumber :: JSONLike j s a o f => j -> Bool
- isString :: JSONLike j s a o f => j -> Bool
- isArray :: JSONLike j s a o f => j -> Bool
- isObject :: JSONLike j s a o f => j -> Bool
- numberOr :: JSONLike j s a o f => Rational -> j -> Rational
- stringOr :: JSONLike j s a o f => s -> j -> s
- arrayOr :: JSONLike j s a o f => a j -> j -> a j
- objectOr :: JSONLike j s a o f => o j -> j -> o j
- fieldsOr :: JSONField j f => [f] -> j -> [f]
- valuesOr :: JSONField j f => [j] -> j -> [j]
- numberOrZero :: JSONLike j s a o f => j -> Rational
- stringOrEmpty :: (JSONLike j s a o f, Monoid s) => j -> s
- arrayOrEmpty :: (JSONLike j s a o f, Monoid (a j)) => j -> a j
- objectOrEmpty :: (JSONLike j s a o f, Monoid (o j)) => j -> o j
- objectFieldsOrEmpty :: (JSONField j f, Monoid (o j)) => j -> [f]
- objectValuesOrEmpty :: (JSONField j f, Monoid (o j)) => j -> [j]
- usingNumber :: JSONLike j s a o f => x -> (Rational -> x) -> j -> x
- usingString :: JSONLike j s a o f => x -> (s -> x) -> j -> x
- usingArray :: JSONLike j s a o f => x -> (a j -> x) -> j -> x
- usingObject :: JSONLike j s a o f => x -> (o j -> x) -> j -> x
- usingObjectFields :: JSONField j f => a -> ([f] -> a) -> j -> a
- usingObjectValues :: JSONField j f => a -> ([j] -> a) -> j -> a
- hasField :: JSONField j f => f -> j -> Bool
- (-?) :: JSONField j f => f -> j -> Bool
- (-|) :: JSONField j s => s -> j -> Maybe j
- fieldOr :: JSONField j f => f -> j -> j -> j
- fieldOrNull :: (JSONLike j s a o f, JSONField j f) => f -> j -> j
- fieldOrTrue :: (JSONLike j s a o f, JSONField j f) => f -> j -> j
- fieldOrFalse :: (JSONLike j s a o f, JSONField j f) => f -> j -> j
- fieldOrZero :: (JSONLike j s a o f, JSONField j f) => f -> j -> j
- fieldOrEmptyString :: (JSONLike j s a o f, JSONField j f, Monoid s) => f -> j -> j
- fieldOrEmptyArray :: (JSONLike j s a o f, JSONField j f, Monoid (a j)) => f -> j -> j
- fieldOrEmptyObject :: (JSONLike j s a o f, JSONField j f, Monoid (o j)) => f -> j -> j
- hasField' :: (JSONField j f, Foldable t) => t f -> j -> Bool
- (-??) :: (JSONField j f, Foldable t) => t f -> j -> Bool
- field' :: (JSONField j f, Foldable t) => t f -> j -> Maybe j
- (-||) :: (JSONField j f, Foldable t) => t f -> j -> Maybe j
- field'Or :: (JSONField j f, Foldable t) => j -> t f -> j -> j
- field'OrNull :: (JSONLike j s a o f, JSONField j f, Foldable t) => t f -> j -> j
- field'OrTrue :: (JSONLike j s a o f, JSONField j f, Foldable t) => t f -> j -> j
- field'OrFalse :: (JSONLike j s a o f, JSONField j f, Foldable t) => t f -> j -> j
- field'OrZero :: (JSONLike j s a o f, JSONField j f, Foldable t) => t f -> j -> j
- field'OrEmptyString :: (JSONLike j s a o f, JSONField j f, Foldable t, Monoid s) => t f -> j -> j
- field'OrEmptyArray :: (JSONLike j s a o f, JSONField j f, Foldable t, Monoid (a j)) => t f -> j -> j
- field'OrEmptyObject :: (JSONLike j s a o f, JSONField j f, Foldable t, Monoid (o j)) => t f -> j -> j
- interactJSON :: (JSONPrint j' s, JSONParse j s e, Interact s) => (Either e j -> j') -> IO ()
- interactJSON' :: (JSONPrint j' s, JSONParse j s e, Interact s) => (e -> j') -> (j -> j') -> IO ()
- withJSON :: (Interact p, Interact s, JSONPrint j' s, JSONParse j p e) => (e -> IO ()) -> (j -> j') -> IO ()
- readJSONFile :: (JSONParse j a e, InteractFile a) => FilePath -> IO (Either e j)
- writeJSONFile :: (InteractFile b, JSONPrint a b) => FilePath -> a -> IO ()
- interactJSONFile :: (InteractFile p, InteractFile s, JSONPrint j' s, JSONParse j p e) => (Either e j -> j') -> FilePath -> FilePath -> IO ()
- interactJSONFile' :: (InteractFile p, InteractFile s, JSONPrint j' s, JSONParse j p e) => (e -> j') -> (j -> j') -> FilePath -> FilePath -> IO ()
- withJSONFile :: (InteractFile p, InteractFile s, JSONPrint j' s, JSONParse j p e) => (e -> IO ()) -> (j -> j') -> FilePath -> FilePath -> IO ()
- module Text.JSON.JSONLike
- module Text.JSON.JSONField
- module Text.JSON.JSONParse
- module Text.JSON.JSONPrepend
- module Text.JSON.JSONPrint
Transformers
Runs the given function if the JSON value is a number.
:: JSONLike j s a o f | |
=> (s -> s) | |
-> j | The JSON value. |
-> j |
Runs the given function if the JSON value is a string.
:: JSONLike j s a o f | |
=> (a j -> a j) | |
-> j | The JSON value. |
-> j |
Runs the given function if the JSON value is an array.
:: JSONLike j s a o f | |
=> (o j -> o j) | |
-> j | The JSON value. |
-> j |
Runs the given function if the JSON value is an object.
Runs the given function on the fields if the JSON value is an object.
Constructors
jemptystring :: (Monoid s, JSONLike j s a o f) => jSource
The JSON value empty string.
jemptyarray :: (Monoid (a j), JSONLike j s a o f) => jSource
The JSON value empty array.
jemptyobject :: (Monoid (o j), JSONLike j s a o f) => jSource
The JSON value empty object.
jsinglearray :: (Applicative a, JSONLike j s a o f) => j -> jSource
Puts a single value into a JSON array.
jsingleobject :: (Applicative o, JSONLike j s a o f) => j -> jSource
Puts a single value into a JSON object.
Accessors
Returns the potential boolean value of a JSON value.
Returns the potential number value of a JSON value.
Returns the potential string value of a JSON value.
Returns the potential array value of a JSON value.
Returns the potential object value of a JSON value.
Decisions
Returns whether or not a JSON is a boolean value.
Returns whether or not a JSON is a boolean with the value true.
Returns whether or not a JSON is a boolean with the value false.
Returns whether or not a JSON is a number value.
Returns whether or not a JSON is a string value.
Returns whether or not a JSON is an array value.
Returns whether or not a JSON is an object value.
Accessors with default
Returns a number value from a JSON value or if it is not a number, returns the given default.
:: JSONLike j s a o f | |
=> 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.
:: JSONLike j s a o f | |
=> 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.
:: JSONLike j s a o f | |
=> 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.
:: 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.
:: 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.
Returns a number value from a JSON value or if it is not a number, returns zero.
Returns a string value from a JSON value or if it is not a string, returns an empty string.
Returns an array value from a JSON value or if it is not an array, returns an empty array.
Returns an object value from a JSON value or if it is not an object, returns an empty object.
Returns an object's fields from a JSON value or if it is not an object, returns no fields.
Returns an object's values from a JSON value or if it is not an object, returns no values.
Combinators
Runs a function on the number of a JSON value or if it is not a number, returns the given default.
:: JSONLike j s a o f | |
=> 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.
:: JSONLike j s a o f | |
=> 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.
:: JSONLike j s a o f | |
=> 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.
:: 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.
:: 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
Whether or not a JSON value is an object with the given field.
Whether or not a JSON value is an object with the given field. An alias for hasField
.
Returns the possible value associated with the given field if this is an object. An alias for field
.
:: 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.
Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON null.
Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON true.
Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON false.
Returns the value associated with the given field or if this is not an object or has no associated value, return a JSON zero.
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.
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.
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.
Traverses down JSON objects with the association fields and returns true if the association graph exists.
Traverses down JSON objects with the association fields and returns true if the association graph exists. An alias for hasField'
.
Traverses down JSON objects with the association fields and returns the potential value.
Traverses down JSON objects with the association fields and returns the potential value. An alias for field'
.
Traverses down JSON objects with the association fields and returns the potential value or the given default.
Traverses down JSON objects with the association fields and returns the potential value or a JSON null.
Traverses down JSON objects with the association fields and returns the potential value or a JSON true.
Traverses down JSON objects with the association fields and returns the potential value or a JSON false.
Traverses down JSON objects with the association fields and returns the potential value or a JSON zero.
Traverses down JSON objects with the association fields and returns the potential value or a JSON empty string.
Traverses down JSON objects with the association fields and returns the potential value or a JSON empty array.
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
module Text.JSON.JSONLike
module Text.JSON.JSONField
module Text.JSON.JSONParse
module Text.JSON.JSONPrepend
module Text.JSON.JSONPrint