gi-json-1.0.5: JSON GObject bindings
CopyrightWill Thompson and Iñaki García Etxebarria
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria
Safe HaskellSafe-Inferred
LanguageHaskell2010

GI.Json.Functions

Description

 
Synopsis

Methods

boxedCanDeserialize

boxedCanDeserialize Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> GType

gboxedType: a boxed type

-> NodeType

nodeType: a node type

-> m Bool

Returns: TRUE if the type can be deserialized, and FALSE otherwise

Checks whether it is possible to deserialize a GBoxed of type gboxed_type from a [structjson.Node] of type node_type.

Since: 0.10

boxedCanSerialize

boxedCanSerialize Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> GType

gboxedType: a boxed type

-> m (Bool, NodeType)

Returns: TRUE if the type can be serialized, and FALSE otherwise

Checks whether it is possible to serialize a GBoxed of type gboxed_type into a [structjson.Node].

The type of the node is placed inside node_type if the function returns TRUE, and it's undefined otherwise.

Since: 0.10

boxedDeserialize

boxedDeserialize Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> GType

gboxedType: a boxed type

-> Node

node: a node

-> m (Ptr ())

Returns: the newly allocated boxed data

Deserializes the given [structjson.Node] into a GBoxed of the given type.

Since: 0.10

boxedSerialize

boxedSerialize Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> GType

gboxedType: a boxed type

-> Ptr ()

boxed: a pointer to a boxed of type gboxed_type

-> m (Maybe Node)

Returns: a node with the serialized boxed type

Serializes a pointer to a GBoxed of the given type into a [structjson.Node].

If the serialization is not possible, this function will return NULL.

Since: 0.10

constructGobject

constructGobject Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> GType

gtype: the type of the object to construct

-> Text

data: a JSON data stream

-> Word64

length: length of the data stream

-> m (Maybe Object)

Returns: a new object instance of the given type (Can throw GError)

Deprecated: (Since version 0.10)Use gobjectFromData instead

Deserializes a JSON data stream and creates an instance of the given type

If the given type implements the Serializable interface, it will be asked to deserialize all the JSON members into their respective properties; otherwise, the default implementation will be used to translate the compatible JSON native types.

  • *Note**: the JSON data stream must be an object.

Since: 0.4

fromString

fromString Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Text

str: a valid UTF-8 string containing JSON data

-> m (Maybe Node)

Returns: the root node of the JSON tree (Can throw GError)

Parses the given string and returns the corresponding JSON tree.

If the string is empty, this function will return NULL.

In case of parsing error, this function returns NULL and sets the error appropriately.

Since: 1.2

gobjectDeserialize

gobjectDeserialize Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> GType

gtype: the type of the object to create

-> Node

node: a node of type JSON_NODE_OBJECT describing the object instance for the given type

-> m Object

Returns: The newly created instance

Creates a new GObject instance of the given type, and constructs it using the members of the object in the given node.

Since: 0.10

gobjectFromData

gobjectFromData Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> GType

gtype: the type of the object to construct

-> Text

data: a JSON data stream

-> Int64

length: length of the data stream, or -1 if it is NUL-terminated

-> m (Maybe Object)

Returns: a new object instance of the given type (Can throw GError)

Deserializes a JSON data stream and creates an instance of the given type.

If the type implements the Serializable interface, it will be asked to deserialize all the JSON members into their respective properties; otherwise, the default implementation will be used to translate the compatible JSON native types.

  • *Note**: the JSON data stream must be an object

Since: 0.10

gobjectSerialize

gobjectSerialize Source #

Arguments

:: (HasCallStack, MonadIO m, IsObject a) 
=> a

gobject: the object to serialize

-> m Node

Returns: the newly created JSON tree

Creates a JSON tree representing the passed object instance.

Each member of the returned JSON object will map to a property of the object type.

The returned JSON tree will be returned as a JsonNode with a type of JSON_NODE_OBJECT.

Since: 0.10

gobjectToData

gobjectToData Source #

Arguments

:: (HasCallStack, MonadIO m, IsObject a) 
=> a

gobject: the object to serialize

-> m (Text, Word64)

Returns: a JSON data stream representing the given object

Serializes a GObject instance into a JSON data stream, iterating recursively over each property.

If the given object implements the Serializable interface, it will be asked to serialize all its properties; otherwise, the default implementation will be use to translate the compatible types into JSON native types.

Since: 0.10

gvariantDeserialize

gvariantDeserialize Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Node

jsonNode: the node to convert

-> Maybe Text

signature: a valid GVariant type string

-> m (Maybe GVariant)

Returns: A newly created GVariant (Can throw GError)

Converts a JSON data structure to a GVariant.

If signature is not NULL, it will be used to resolve ambiguous data types.

If no error occurs, the resulting GVariant is guaranteed to conform to signature.

If signature is not NULL but does not represent a valid GVariant type string, NULL is returned and the error is set to G_IO_ERROR_INVALID_ARGUMENT.

If a signature is provided but the JSON structure cannot be mapped to it, NULL is returned and the error is set to G_IO_ERROR_INVALID_DATA.

If signature is NULL, the conversion is done based strictly on the types in the JSON nodes.

The returned variant has a floating reference that will need to be sunk by the caller code.

Since: 0.14

gvariantDeserializeData

gvariantDeserializeData Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Text

json: A JSON data string

-> Int64

length: The length of json, or -1 if NUL-terminated

-> Maybe Text

signature: A valid GVariant type string

-> m (Maybe GVariant)

Returns: A newly created GVariantD compliant (Can throw GError)

Converts a JSON string to a GVariant value.

This function works exactly like gvariantDeserialize, but takes a JSON encoded string instead.

The string is first converted to a [structjson.Node] using Parser, and then json_gvariant_deserialize is called on the node.

The returned variant has a floating reference that will need to be sunk by the caller code.

Since: 0.14

gvariantSerialize

gvariantSerialize Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> GVariant

variant: A GVariant to convert

-> m Node

Returns: the root of the JSON data structure obtained from variant

Converts variant to a JSON tree.

Since: 0.14

gvariantSerializeData

gvariantSerializeData Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> GVariant

variant: A GVariant to convert

-> m (Text, Word64)

Returns: The JSON encoded string corresponding to the given variant

Converts variant to its JSON encoded string representation.

This is a convenience function around gvariantSerialize, to obtain the JSON tree, and then Generator to stringify it.

Since: 0.14

serializeGobject

serializeGobject Source #

Arguments

:: (HasCallStack, MonadIO m, IsObject a) 
=> a

gobject: the object to serialize

-> m (Text, Word64)

Returns: a JSON data stream representing the given object

Deprecated: (Since version 0.10)Use gobjectToData instead

Serializes a GObject instance into a JSON data stream.

If the object implements the Serializable interface, it will be asked to serizalize all its properties; otherwise, the default implementation will be use to translate the compatible types into JSON native types.

stringCompare

stringCompare Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Text

a: a JSON string

-> Text

b: another JSON string

-> m Int32

Returns: an integer less than zero if a < b, equal to zero if a == b, and greater than zero if a > b

Check whether a and b are equal UTF-8 JSON strings and return an ordering over them in strcmp() style.

Since: 1.2

stringEqual

stringEqual Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Text

a: a JSON string

-> Text

b: another JSON string

-> m Bool

Returns: TRUE if a and b are equal; FALSE otherwise

Check whether a and b are equal UTF-8 JSON strings.

Since: 1.2

stringHash

stringHash Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Text

key: a JSON string to hash

-> m Word32

Returns: hash value for key

Calculate a hash value for the given key (a UTF-8 JSON string).

Note: Member names are compared byte-wise, without applying any Unicode decomposition or normalisation. This is not explicitly mentioned in the JSON standard (ECMA-404), but is assumed.

Since: 1.2

toString

toString Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Node

node: a JSON tree

-> Bool

pretty: whether the output should be prettyfied for printing

-> m Text

Returns: the string representation of the node

Generates a stringified JSON representation of the contents of the given node.

Since: 1.2