Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
- Exported types
- Methods
- addMember
- dupMember
- equal
- foreachMember
- getArrayMember
- getBooleanMember
- getBooleanMemberWithDefault
- getDoubleMember
- getDoubleMemberWithDefault
- getIntMember
- getIntMemberWithDefault
- getMember
- getMembers
- getNullMember
- getObjectMember
- getSize
- getStringMember
- getStringMemberWithDefault
- getValues
- hasMember
- hash
- isImmutable
- new
- ref
- removeMember
- seal
- setArrayMember
- setBooleanMember
- setDoubleMember
- setIntMember
- setMember
- setNullMember
- setObjectMember
- setStringMember
- unref
JsonObject
is the representation of the object type inside JSON.
A JsonObject
contains [structjson
.Node] "members", which may contain
fundamental types, arrays or other objects; each member of an object is
accessed using a unique string, or "name".
Since objects can be arbitrarily big, copying them can be expensive; for
this reason they are reference counted. You can control the lifetime of
a JsonObject
using [methodjson
.Object.ref] and [methodjson
.Object.unref].
To add or overwrite a member with a given name, use [methodjson
.Object.set_member].
To extract a member with a given name, use [methodjson
.Object.get_member].
To retrieve the list of members, use [methodjson
.Object.get_members].
To retrieve the size of the object (that is, the number of members it has),
use [methodjson
.Object.get_size].
Synopsis
- newtype Object = Object (ManagedPtr Object)
- objectAddMember :: (HasCallStack, MonadIO m) => Object -> Text -> Node -> m ()
- objectDupMember :: (HasCallStack, MonadIO m) => Object -> Text -> m (Maybe Node)
- objectEqual :: (HasCallStack, MonadIO m) => Object -> Object -> m Bool
- objectForeachMember :: (HasCallStack, MonadIO m) => Object -> ObjectForeach -> m ()
- objectGetArrayMember :: (HasCallStack, MonadIO m) => Object -> Text -> m (Maybe Array)
- objectGetBooleanMember :: (HasCallStack, MonadIO m) => Object -> Text -> m Bool
- objectGetBooleanMemberWithDefault :: (HasCallStack, MonadIO m) => Object -> Text -> Bool -> m Bool
- objectGetDoubleMember :: (HasCallStack, MonadIO m) => Object -> Text -> m Double
- objectGetDoubleMemberWithDefault :: (HasCallStack, MonadIO m) => Object -> Text -> Double -> m Double
- objectGetIntMember :: (HasCallStack, MonadIO m) => Object -> Text -> m Int64
- objectGetIntMemberWithDefault :: (HasCallStack, MonadIO m) => Object -> Text -> Int64 -> m Int64
- objectGetMember :: (HasCallStack, MonadIO m) => Object -> Text -> m (Maybe Node)
- objectGetMembers :: (HasCallStack, MonadIO m) => Object -> m [Text]
- objectGetNullMember :: (HasCallStack, MonadIO m) => Object -> Text -> m Bool
- objectGetObjectMember :: (HasCallStack, MonadIO m) => Object -> Text -> m (Maybe Object)
- objectGetSize :: (HasCallStack, MonadIO m) => Object -> m Word32
- objectGetStringMember :: (HasCallStack, MonadIO m) => Object -> Text -> m Text
- objectGetStringMemberWithDefault :: (HasCallStack, MonadIO m) => Object -> Text -> Text -> m Text
- objectGetValues :: (HasCallStack, MonadIO m) => Object -> m [Node]
- objectHasMember :: (HasCallStack, MonadIO m) => Object -> Text -> m Bool
- objectHash :: (HasCallStack, MonadIO m) => Object -> m Word32
- objectIsImmutable :: (HasCallStack, MonadIO m) => Object -> m Bool
- objectNew :: (HasCallStack, MonadIO m) => m Object
- objectRef :: (HasCallStack, MonadIO m) => Object -> m Object
- objectRemoveMember :: (HasCallStack, MonadIO m) => Object -> Text -> m ()
- objectSeal :: (HasCallStack, MonadIO m) => Object -> m ()
- objectSetArrayMember :: (HasCallStack, MonadIO m) => Object -> Text -> Array -> m ()
- objectSetBooleanMember :: (HasCallStack, MonadIO m) => Object -> Text -> Bool -> m ()
- objectSetDoubleMember :: (HasCallStack, MonadIO m) => Object -> Text -> Double -> m ()
- objectSetIntMember :: (HasCallStack, MonadIO m) => Object -> Text -> Int64 -> m ()
- objectSetMember :: (HasCallStack, MonadIO m) => Object -> Text -> Node -> m ()
- objectSetNullMember :: (HasCallStack, MonadIO m) => Object -> Text -> m ()
- objectSetObjectMember :: (HasCallStack, MonadIO m) => Object -> Text -> Object -> m ()
- objectSetStringMember :: (HasCallStack, MonadIO m) => Object -> Text -> Text -> m ()
- objectUnref :: (HasCallStack, MonadIO m) => Object -> m ()
Exported types
Memory-managed wrapper type.
Instances
Eq Object Source # | |
GBoxed Object Source # | |
Defined in GI.Json.Structs.Object | |
ManagedPtrNewtype Object Source # | |
Defined in GI.Json.Structs.Object toManagedPtr :: Object -> ManagedPtr Object # | |
TypedObject Object Source # | |
Defined in GI.Json.Structs.Object | |
HasParentTypes Object Source # | |
Defined in GI.Json.Structs.Object | |
IsGValue (Maybe Object) Source # | Convert |
Defined in GI.Json.Structs.Object | |
type ParentTypes Object Source # | |
Defined in GI.Json.Structs.Object |
Methods
Click to display all available methods, including inherited ones
Methods
addMember, dupMember, equal, foreachMember, hasMember, hash, isImmutable, ref, removeMember, seal, unref.
Getters
getArrayMember, getBooleanMember, getBooleanMemberWithDefault, getDoubleMember, getDoubleMemberWithDefault, getIntMember, getIntMemberWithDefault, getMember, getMembers, getNullMember, getObjectMember, getSize, getStringMember, getStringMemberWithDefault, getValues.
Setters
setArrayMember, setBooleanMember, setDoubleMember, setIntMember, setMember, setNullMember, setObjectMember, setStringMember.
addMember
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> Node |
|
-> m () |
Deprecated: (Since version 0.8)Use [methodjson
.Object.set_member] instead
Adds a new member for the given name and value into an object.
This function will return if the object already contains a member with the same name.
dupMember
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> m (Maybe Node) | Returns: a copy of the value for the requested object member |
Retrieves a copy of the value of the given member inside an object.
Since: 0.6
equal
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Object |
|
-> m Bool | Returns: |
Check whether a
and b
are equal objects, meaning they have the same
set of members, and the values of corresponding members are equal.
Since: 1.2
foreachMember
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> ObjectForeach |
|
-> m () |
Iterates over all members of object
and calls func
on
each one of them.
It is safe to change the value of a member of the oobject from within the iterator function, but it is not safe to add or remove members from the object.
The order in which the object members are iterated is the insertion order.
Since: 0.8
getArrayMember
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> m (Maybe Array) | Returns: the array inside the object's member |
Convenience function that retrieves the array
stored in memberName
of object
. It is an error to specify a
memberName
which does not exist.
If memberName
contains null
, then this function will return NULL
.
See also: [methodjson
.Object.get_member], [methodjson
.Object.has_member]
Since: 0.8
getBooleanMember
objectGetBooleanMember Source #
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> m Bool | Returns: the boolean value of the object's member |
Convenience function that retrieves the boolean value
stored in memberName
of object
. It is an error to specify a
memberName
which does not exist.
See also: [methodjson
.Object.get_boolean_member_with_default],
[methodjson
.Object.get_member], [methodjson
.Object.has_member]
Since: 0.8
getBooleanMemberWithDefault
objectGetBooleanMemberWithDefault Source #
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> Bool |
|
-> m Bool | Returns: the boolean value of the object's member, or the given default |
Convenience function that retrieves the boolean value
stored in memberName
of object
.
If memberName
does not exist, does not contain a scalar value,
or contains null
, then defaultValue
is returned instead.
Since: 1.6
getDoubleMember
objectGetDoubleMember Source #
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> m Double | Returns: the floating point value of the object's member |
Convenience function that retrieves the floating point value
stored in memberName
of object
. It is an error to specify a
memberName
which does not exist.
See also: [methodjson
.Object.get_double_member_with_default],
[methodjson
.Object.get_member], [methodjson
.Object.has_member]
Since: 0.8
getDoubleMemberWithDefault
objectGetDoubleMemberWithDefault Source #
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> Double |
|
-> m Double | Returns: the floating point value of the object's member, or the given default |
Convenience function that retrieves the floating point value
stored in memberName
of object
.
If memberName
does not exist, does not contain a scalar value,
or contains null
, then defaultValue
is returned instead.
Since: 1.6
getIntMember
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> m Int64 | Returns: the integer value of the object's member |
Convenience function that retrieves the integer value
stored in memberName
of object
. It is an error to specify a
memberName
which does not exist.
See also: [methodjson
.Object.get_int_member_with_default],
[methodjson
.Object.get_member], [methodjson
.Object.has_member]
Since: 0.8
getIntMemberWithDefault
objectGetIntMemberWithDefault Source #
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> Int64 |
|
-> m Int64 | Returns: the integer value of the object's member, or the given default |
Convenience function that retrieves the integer value
stored in memberName
of object
.
If memberName
does not exist, does not contain a scalar value,
or contains null
, then defaultValue
is returned instead.
Since: 1.6
getMember
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> m (Maybe Node) | Returns: the value for the requested object member |
Retrieves the value of the given member inside an object.
getMembers
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> m [Text] | Returns: the member names of the object |
Retrieves all the names of the members of an object.
You can obtain the value for each member by iterating the returned list
and calling [methodjson
.Object.get_member].
getNullMember
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> m Bool | Returns: |
Convenience function that checks whether the value
stored in memberName
of object
is null. It is an error to
specify a memberName
which does not exist.
See also: [methodjson
.Object.get_member], [methodjson
.Object.has_member]
Since: 0.8
getObjectMember
objectGetObjectMember Source #
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> m (Maybe Object) | Returns: the object inside the object's member |
Convenience function that retrieves the object
stored in memberName
of object
. It is an error to specify a memberName
which does not exist.
If memberName
contains null
, then this function will return NULL
.
See also: [methodjson
.Object.get_member], [methodjson
.Object.has_member]
Since: 0.8
getSize
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> m Word32 | Returns: the number of members |
Retrieves the number of members of a JSON object.
getStringMember
objectGetStringMember Source #
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> m Text | Returns: the string value of the object's member |
Convenience function that retrieves the string value
stored in memberName
of object
. It is an error to specify a
memberName
that does not exist.
See also: [methodjson
.Object.get_string_member_with_default],
[methodjson
.Object.get_member], [methodjson
.Object.has_member]
Since: 0.8
getStringMemberWithDefault
objectGetStringMemberWithDefault Source #
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> Text |
|
-> m Text | Returns: the string value of the object's member, or the given default |
Convenience function that retrieves the string value
stored in memberName
of object
.
If memberName
does not exist, does not contain a scalar value,
or contains null
, then defaultValue
is returned instead.
Since: 1.6
getValues
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> m [Node] | Returns: the member values of the object |
Retrieves all the values of the members of an object.
hasMember
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> m Bool | Returns: |
Checks whether object
has a member named memberName
.
hash
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> m Word32 | Returns: hash value for |
Calculate a hash value for the given key
(a JSON object).
The hash is calculated over the object and all its members, recursively. If the object is immutable, this is a fast operation; otherwise, it scales proportionally with the number of members in the object.
Since: 1.2
isImmutable
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> m Bool | Returns: |
Checks whether the given object has been marked as immutable by calling
[methodjson
.Object.seal] on it.
Since: 1.2
new
:: (HasCallStack, MonadIO m) | |
=> m Object | Returns: the newly created object |
Creates a new object.
ref
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> m Object | Returns: the given object, with the reference count increased by one. |
Acquires a reference on the given object.
removeMember
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> m () |
Removes memberName
from object
, freeing its allocated resources.
seal
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> m () |
Seals the object, making it immutable to further changes.
This function will recursively seal all members of the object too.
If the object is already immutable, this is a no-op.
Since: 1.2
setArrayMember
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> Array |
|
-> m () |
Convenience function for setting an object member with an array value.
See also: [methodjson
.Object.set_member], [methodjson
.Node.take_array]
Since: 0.8
setBooleanMember
objectSetBooleanMember Source #
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> Bool |
|
-> m () |
Convenience function for setting an object member with a boolean value.
See also: [methodjson
.Object.set_member], [methodjson
.Node.init_boolean]
Since: 0.8
setDoubleMember
objectSetDoubleMember Source #
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> Double |
|
-> m () |
Convenience function for setting an object member with a floating point value.
See also: [methodjson
.Object.set_member], [methodjson
.Node.init_double]
Since: 0.8
setIntMember
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> Int64 |
|
-> m () |
Convenience function for setting an object member with an integer value.
See also: [methodjson
.Object.set_member], [methodjson
.Node.init_int]
Since: 0.8
setMember
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> Node |
|
-> m () |
Sets the value of a member inside an object.
If the object does not have a member with the given name, a new member is created.
If the object already has a member with the given name, the current value is overwritten with the new.
Since: 0.8
setNullMember
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> m () |
Convenience function for setting an object member with a null
value.
See also: [methodjson
.Object.set_member], [methodjson
.Node.init_null]
Since: 0.8
setObjectMember
objectSetObjectMember Source #
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> Object |
|
-> m () |
Convenience function for setting an object member with an object value.
See also: [methodjson
.Object.set_member], [methodjson
.Node.take_object]
Since: 0.8
setStringMember
objectSetStringMember Source #
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> Text |
|
-> Text |
|
-> m () |
Convenience function for setting an object member with a string value.
See also: [methodjson
.Object.set_member], [methodjson
.Node.init_string]
Since: 0.8
unref
:: (HasCallStack, MonadIO m) | |
=> Object |
|
-> m () |
Releases a reference on the given object.
If the reference count reaches zero, the object is destroyed and all its resources are freed.