json-types

json-types

Synopsis

#define             JSON_NODE_TYPE                      (node)
#define             JSON_TYPE_NODE
#define             JSON_TYPE_OBJECT
#define             JSON_TYPE_ARRAY
                    JsonObject;
                    JsonArray;
                    JsonNode;
enum                JsonNodeType;
GType               json_node_get_type                  (void);
JsonNode *          json_node_new                       (JsonNodeType type);
JsonNode *          json_node_copy                      (JsonNode *node);
void                json_node_free                      (JsonNode *node);
GType               json_node_get_value_type            (JsonNode *node);
void                json_node_set_object                (JsonNode *node,
                                                         JsonObject *object);
void                json_node_take_object               (JsonNode *node,
                                                         JsonObject *object);
JsonObject *        json_node_get_object                (JsonNode *node);
JsonObject *        json_node_dup_object                (JsonNode *node);
void                json_node_set_array                 (JsonNode *node,
                                                         JsonArray *array);
void                json_node_take_array                (JsonNode *node,
                                                         JsonArray *array);
JsonArray *         json_node_get_array                 (JsonNode *node);
JsonArray *         json_node_dup_array                 (JsonNode *node);
void                json_node_set_value                 (JsonNode *node,
                                                         const GValue *value);
void                json_node_get_value                 (JsonNode *node,
                                                         GValue *value);
void                json_node_set_string                (JsonNode *node,
                                                         const gchar *value);
const gchar *       json_node_get_string                (JsonNode *node);
gchar *             json_node_dup_string                (JsonNode *node);
void                json_node_set_int                   (JsonNode *node,
                                                         gint value);
gint                json_node_get_int                   (JsonNode *node);
void                json_node_set_double                (JsonNode *node,
                                                         gdouble value);
gdouble             json_node_get_double                (JsonNode *node);
void                json_node_set_boolean               (JsonNode *node,
                                                         gboolean value);
gboolean            json_node_get_boolean               (JsonNode *node);
JsonNode *          json_node_get_parent                (JsonNode *node);
const gchar *       json_node_type_name                 (JsonNode *node);
GType               json_object_get_type                (void);
JsonObject *        json_object_new                     (void);
JsonObject *        json_object_ref                     (JsonObject *object);
void                json_object_unref                   (JsonObject *object);
void                json_object_add_member              (JsonObject *object,
                                                         const gchar *member_name,
                                                         JsonNode *node);
GList *             json_object_get_members             (JsonObject *object);
JsonNode *          json_object_get_member              (JsonObject *object,
                                                         const gchar *member_name);
JsonNode *          json_object_dup_member              (JsonObject *object,
                                                         const gchar *member_name);
gboolean            json_object_has_member              (JsonObject *object,
                                                         const gchar *member_name);
void                json_object_remove_member           (JsonObject *object,
                                                         const gchar *member_name);
GList *             json_object_get_values              (JsonObject *object);
guint               json_object_get_size                (JsonObject *object);
GType               json_array_get_type                 (void);
JsonArray *         json_array_new                      (void);
JsonArray *         json_array_sized_new                (guint n_elements);
JsonArray *         json_array_ref                      (JsonArray *array);
void                json_array_unref                    (JsonArray *array);
void                json_array_add_element              (JsonArray *array,
                                                         JsonNode *node);
GList *             json_array_get_elements             (JsonArray *array);
JsonNode *          json_array_get_element              (JsonArray *array,
                                                         guint index_);
JsonNode *          json_array_dup_element              (JsonArray *array,
                                                         guint index_);
void                json_array_remove_element           (JsonArray *array,
                                                         guint index_);
guint               json_array_get_length               (JsonArray *array);

Description

Details

JSON_NODE_TYPE()

#define JSON_NODE_TYPE(node)    (((JsonNode *) (node))->type)

Evaluates to the JsonNodeType contained by node

node :

a JsonNode

JSON_TYPE_NODE

#define JSON_TYPE_NODE          (json_node_get_type ())

JSON_TYPE_OBJECT

#define JSON_TYPE_OBJECT        (json_object_get_type ())

JSON_TYPE_ARRAY

#define JSON_TYPE_ARRAY         (json_array_get_type ())

JsonObject

typedef struct _JsonObject JsonObject;

A JSON object type. The contents of the JsonObject structure are private and should only be accessed by the provided API


JsonArray

typedef struct _JsonArray JsonArray;

A JSON array type. The contents of the JsonArray structure are private and should only be accessed by the provided API


JsonNode

typedef struct {
} JsonNode;

A generic container of JSON data types. The contents of the JsonNode structure are private and should only be accessed via the provided functions and never directly.

JsonNodeType type;

the type of node

enum JsonNodeType

typedef enum {
	JSON_NODE_OBJECT,
	JSON_NODE_ARRAY,
	JSON_NODE_VALUE,
	JSON_NODE_NULL
} JsonNodeType;

Indicates the content of a JsonNode.

JSON_NODE_OBJECT

The node contains a JsonObject

JSON_NODE_ARRAY

The node contains a JsonArray

JSON_NODE_VALUE

The node contains a fundamental type

JSON_NODE_NULL

Special type, for nodes containing null

json_node_get_type ()

GType               json_node_get_type                  (void);

json_node_new ()

JsonNode *          json_node_new                       (JsonNodeType type);

Creates a new JsonNode of type.

type :

a JsonNodeType

Returns :

the newly created JsonNode

json_node_copy ()

JsonNode *          json_node_copy                      (JsonNode *node);

Copies node. If the node contains complex data types then the reference count of the objects is increased.

node :

a JsonNode

Returns :

the copied JsonNode

json_node_free ()

void                json_node_free                      (JsonNode *node);

Frees the resources allocated by node.

node :

a JsonNode

json_node_get_value_type ()

GType               json_node_get_value_type            (JsonNode *node);

Returns the GType of the payload of the node.

node :

a JsonNode

Returns :

a GType for the payload.

Since 0.4


json_node_set_object ()

void                json_node_set_object                (JsonNode *node,
                                                         JsonObject *object);

Sets objects inside node. The reference count of object is increased.

node :

a JsonNode

object :

a JsonObject

json_node_take_object ()

void                json_node_take_object               (JsonNode *node,
                                                         JsonObject *object);

Sets object inside node. The reference count of object is not increased.

node :

a JsonNode

object :

a JsonObject

json_node_get_object ()

JsonObject *        json_node_get_object                (JsonNode *node);

Retrieves the JsonObject stored inside a JsonNode

node :

a JsonNode

Returns :

the JsonObject

json_node_dup_object ()

JsonObject *        json_node_dup_object                (JsonNode *node);

Retrieves the JsonObject inside node. The reference count of the returned object is increased.

node :

a JsonNode

Returns :

the JsonObject

json_node_set_array ()

void                json_node_set_array                 (JsonNode *node,
                                                         JsonArray *array);

Sets array inside node and increases the JsonArray reference count

node :

a JsonNode

array :

a JsonArray

json_node_take_array ()

void                json_node_take_array                (JsonNode *node,
                                                         JsonArray *array);

Sets array into node without increasing the JsonArray reference count.

node :

a JsonNode

array :

a JsonArray

json_node_get_array ()

JsonArray *         json_node_get_array                 (JsonNode *node);

Retrieves the JsonArray stored inside a JsonNode

node :

a JsonNode

Returns :

the JsonArray

json_node_dup_array ()

JsonArray *         json_node_dup_array                 (JsonNode *node);

Retrieves the JsonArray stored inside a JsonNode and returns it with its reference count increased by one.

node :

a JsonNode

Returns :

the JsonArray with its reference count increased.

json_node_set_value ()

void                json_node_set_value                 (JsonNode *node,
                                                         const GValue *value);

Sets value inside node. The passed GValue is copied into the JsonNode

node :

a JsonNode

value :

the GValue to set

json_node_get_value ()

void                json_node_get_value                 (JsonNode *node,
                                                         GValue *value);

Retrieves a value from a JsonNode and copies into value. When done using it, call g_value_unset() on the GValue.

node :

a JsonNode

value :

return location for an uninitialized value

json_node_set_string ()

void                json_node_set_string                (JsonNode *node,
                                                         const gchar *value);

Sets value as the string content of the node, replacing any existing content.

node :

a JsonNode of type JSON_NODE_VALUE

value :

a string value

json_node_get_string ()

const gchar *       json_node_get_string                (JsonNode *node);

Gets the string value stored inside a JsonNode

node :

a JsonNode of type JSON_NODE_VALUE

Returns :

a string value.

json_node_dup_string ()

gchar *             json_node_dup_string                (JsonNode *node);

Gets a copy of the string value stored inside a JsonNode

node :

a JsonNode of type JSON_NODE_VALUE

Returns :

a newly allocated string containing a copy of the JsonNode contents

json_node_set_int ()

void                json_node_set_int                   (JsonNode *node,
                                                         gint value);

Sets value as the integer content of the node, replacing any existing content.

node :

a JsonNode of type JSON_NODE_VALUE

value :

an integer value

json_node_get_int ()

gint                json_node_get_int                   (JsonNode *node);

Gets the integer value stored inside a JsonNode

node :

a JsonNode of type JSON_NODE_VALUE

Returns :

an integer value.

json_node_set_double ()

void                json_node_set_double                (JsonNode *node,
                                                         gdouble value);

Sets value as the double content of the node, replacing any existing content.

node :

a JsonNode of type JSON_NODE_VALUE

value :

a double value

json_node_get_double ()

gdouble             json_node_get_double                (JsonNode *node);

Gets the double value stored inside a JsonNode

node :

a JsonNode of type JSON_NODE_VALUE

Returns :

a double value.

json_node_set_boolean ()

void                json_node_set_boolean               (JsonNode *node,
                                                         gboolean value);

Sets value as the boolean content of the node, replacing any existing content.

node :

a JsonNode of type JSON_NODE_VALUE

value :

a boolean value

json_node_get_boolean ()

gboolean            json_node_get_boolean               (JsonNode *node);

Gets the boolean value stored inside a JsonNode

node :

a JsonNode of type JSON_NODE_VALUE

Returns :

a boolean value.

json_node_get_parent ()

JsonNode *          json_node_get_parent                (JsonNode *node);

Retrieves the parent JsonNode of node.

node :

a JsonNode

Returns :

the parent node, or NULL if node is the root node

json_node_type_name ()

const gchar *       json_node_type_name                 (JsonNode *node);

Retrieves the user readable name of the data type contained by node.

node :

a JsonNode

Returns :

a string containing the name of the type. The returned string is owned by the node and should never be modified or freed

json_object_get_type ()

GType               json_object_get_type                (void);

json_object_new ()

JsonObject *        json_object_new                     (void);

Creates a new JsonObject, an JSON object type representation.

Returns :

the newly created JsonObject

json_object_ref ()

JsonObject *        json_object_ref                     (JsonObject *object);

Increase by one the reference count of a JsonObject.

object :

a JsonObject

Returns :

the passed JsonObject, with the reference count increased by one.

json_object_unref ()

void                json_object_unref                   (JsonObject *object);

Decreases by one the reference count of a JsonObject. If the reference count reaches zero, the object is destroyed and all its allocated resources are freed.

object :

a JsonObject

json_object_add_member ()

void                json_object_add_member              (JsonObject *object,
                                                         const gchar *member_name,
                                                         JsonNode *node);

Adds a member named member_name and containing node into a JsonObject. The object will take ownership of the JsonNode.

object :

a JsonObject

member_name :

the name of the member

node :

the value of the member

json_object_get_members ()

GList *             json_object_get_members             (JsonObject *object);

Retrieves all the names of the members of a JsonObject. You can obtain the value for each member using json_object_get_member().

object :

a JsonObject

Returns :

a GList of member names. The content of the list is owned by the JsonObject and should never be modified or freed. When you have finished using the returned list, use g_list_free() to free the resources it has allocated.

json_object_get_member ()

JsonNode *          json_object_get_member              (JsonObject *object,
                                                         const gchar *member_name);

Retrieves the JsonNode containing the value of member_name inside a JsonObject.

object :

a JsonObject

member_name :

the name of the JSON object member to access

Returns :

a pointer to the node for the requested object member, or NULL

json_object_dup_member ()

JsonNode *          json_object_dup_member              (JsonObject *object,
                                                         const gchar *member_name);

Retrieves a copy of the JsonNode containing the value of member_name inside a JsonObject

object :

a JsonObject

member_name :

the name of the JSON object member to access

Returns :

a copy of the node for the requested object member or NULL. Use json_node_free() when done.

Since 0.6


json_object_has_member ()

gboolean            json_object_has_member              (JsonObject *object,
                                                         const gchar *member_name);

Checks whether object has a member named member_name.

object :

a JsonObject

member_name :

the name of a JSON object member

Returns :

TRUE if the JSON object has the requested member

json_object_remove_member ()

void                json_object_remove_member           (JsonObject *object,
                                                         const gchar *member_name);

Removes member_name from object, freeing its allocated resources.

object :

a JsonObject

member_name :

the name of the member to remove

json_object_get_values ()

GList *             json_object_get_values              (JsonObject *object);

Retrieves all the values of the members of a JsonObject.

object :

a JsonObject

Returns :

a GList of JsonNodes. The content of the list is owned by the JsonObject and should never be modified or freed. When you have finished using the returned list, use g_list_free() to free the resources it has allocated.

json_object_get_size ()

guint               json_object_get_size                (JsonObject *object);

Retrieves the number of members of a JsonObject.

object :

a JsonObject

Returns :

the number of members

json_array_get_type ()

GType               json_array_get_type                 (void);

json_array_new ()

JsonArray *         json_array_new                      (void);

Creates a new JsonArray.

Returns :

the newly created JsonArray

json_array_sized_new ()

JsonArray *         json_array_sized_new                (guint n_elements);

Creates a new JsonArray with n_elements slots already allocated.

n_elements :

number of slots to pre-allocate

Returns :

the newly created JsonArray

json_array_ref ()

JsonArray *         json_array_ref                      (JsonArray *array);

Increase by one the reference count of a JsonArray.

array :

a JsonArray

Returns :

the passed JsonArray, with the reference count increased by one.

json_array_unref ()

void                json_array_unref                    (JsonArray *array);

Decreases by one the reference count of a JsonArray. If the reference count reaches zero, the array is destroyed and all its allocated resources are freed.

array :

a JsonArray

json_array_add_element ()

void                json_array_add_element              (JsonArray *array,
                                                         JsonNode *node);

Appends node inside array. The array will take ownership of the JsonNode.

array :

a JsonArray

node :

a JsonNode

json_array_get_elements ()

GList *             json_array_get_elements             (JsonArray *array);

Gets the elements of a JsonArray as a list of JsonNodes.

array :

a JsonArray

Returns :

a GList containing the elements of the array. The contents of the list are owned by the array and should never be modified or freed. Use g_list_free() on the returned list when done using it

json_array_get_element ()

JsonNode *          json_array_get_element              (JsonArray *array,
                                                         guint index_);

Retrieves the JsonNode containing the value of the element at index_ inside a JsonArray.

array :

a JsonArray

index_ :

the index of the element to retrieve

Returns :

a pointer to the JsonNode at the requested index

json_array_dup_element ()

JsonNode *          json_array_dup_element              (JsonArray *array,
                                                         guint index_);

Retrieves a copy of the JsonNode containing the value of the element at index_ inside a JsonArray

array :

a JsonArray

index_ :

the index of the element to retrieve

Returns :

a copy of the JsonNode at the requested index. Use json_node_free() when done.

Since 0.6


json_array_remove_element ()

void                json_array_remove_element           (JsonArray *array,
                                                         guint index_);

Removes the JsonNode inside array at index_ freeing its allocated resources.

array :

a JsonArray

index_ :

the position of the element to be removed

json_array_get_length ()

guint               json_array_get_length               (JsonArray *array);

Retrieves the length of a JsonArray

array :

a JsonArray

Returns :

the length of the array