1 /* json-types.h - JSON data types
3 * This file is part of JSON-GLib
4 * Copyright (C) 2007 OpenedHand Ltd.
5 * Copyright (C) 2009 Intel Corp.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 * Emmanuele Bassi <ebassi@linux.intel.com>
24 #if !defined(__JSON_GLIB_INSIDE__) && !defined(JSON_COMPILATION)
25 #error "Only <json-glib/json-glib.h> can be included directly."
28 #ifndef __JSON_TYPES_H__
29 #define __JSON_TYPES_H__
31 #include <glib-object.h>
39 * Evaluates to the #JsonNodeType contained by @node
41 #define JSON_NODE_TYPE(node) (json_node_get_node_type ((node)))
48 * Evaluates to %TRUE if the @node holds type @t
52 #define JSON_NODE_HOLDS(node,t) (json_node_get_node_type ((node)) == (t))
55 * JSON_NODE_HOLDS_VALUE:
58 * Evaluates to %TRUE if @node holds a %JSON_NODE_VALUE
62 #define JSON_NODE_HOLDS_VALUE(node) (JSON_NODE_HOLDS ((node), JSON_NODE_VALUE))
65 * JSON_NODE_HOLDS_OBJECT:
68 * Evaluates to %TRUE if @node holds a %JSON_NODE_OBJECT
72 #define JSON_NODE_HOLDS_OBJECT(node) (JSON_NODE_HOLDS ((node), JSON_NODE_OBJECT))
75 * JSON_NODE_HOLDS_ARRAY:
78 * Evaluates to %TRUE if @node holds a %JSON_NODE_ARRAY
82 #define JSON_NODE_HOLDS_ARRAY(node) (JSON_NODE_HOLDS ((node), JSON_NODE_ARRAY))
85 * JSON_NODE_HOLDS_NULL:
88 * Evaluates to %TRUE if @node holds a %JSON_NODE_NULL
92 #define JSON_NODE_HOLDS_NULL(node) (JSON_NODE_HOLDS ((node), JSON_NODE_NULL))
94 #define JSON_TYPE_NODE (json_node_get_type ())
95 #define JSON_TYPE_OBJECT (json_object_get_type ())
96 #define JSON_TYPE_ARRAY (json_array_get_type ())
100 * @type: the type of node
102 * A generic container of JSON data types. The contents of the #JsonNode
103 * structure are private and should only be accessed via the provided
104 * functions and never directly.
106 typedef struct _JsonNode JsonNode;
111 * A JSON object type. The contents of the #JsonObject structure are private
112 * and should only be accessed by the provided API
114 typedef struct _JsonObject JsonObject;
119 * A JSON array type. The contents of the #JsonArray structure are private
120 * and should only be accessed by the provided API
122 typedef struct _JsonArray JsonArray;
126 * @JSON_NODE_OBJECT: The node contains a #JsonObject
127 * @JSON_NODE_ARRAY: The node contains a #JsonArray
128 * @JSON_NODE_VALUE: The node contains a fundamental type
129 * @JSON_NODE_NULL: Special type, for nodes containing null
131 * Indicates the content of a #JsonNode.
142 * @object: the iterated #JsonObject
143 * @member_name: the name of the member
144 * @member_node: a #JsonNode containing the @member_name value
145 * @user_data: data passed to the function
147 * The function to be passed to json_object_foreach_member(). You
148 * should not add or remove members to and from @object within
149 * this function. It is safe to change the value of @member_node.
153 typedef void (* JsonObjectForeach) (JsonObject *object,
154 const gchar *member_name,
155 JsonNode *member_node,
160 * @array: the iterated #JsonArray
161 * @index_: the index of the element
162 * @element_node: a #JsonNode containing the value at @index_
163 * @user_data: data passed to the function
165 * The function to be passed to json_array_foreach_element(). You
166 * should not add or remove elements to and from @array within
167 * this function. It is safe to change the value of @element_node.
171 typedef void (* JsonArrayForeach) (JsonArray *array,
173 JsonNode *element_node,
181 GType json_node_get_type (void) G_GNUC_CONST;
182 JsonNode * json_node_new (JsonNodeType type);
183 JsonNode * json_node_copy (JsonNode *node);
184 void json_node_free (JsonNode *node);
185 JsonNodeType json_node_get_node_type (JsonNode *node);
186 GType json_node_get_value_type (JsonNode *node);
187 void json_node_set_parent (JsonNode *node,
189 JsonNode * json_node_get_parent (JsonNode *node);
190 #if !GLIB_CHECK_VERSION(2,31,0)
191 G_CONST_RETURN gchar *json_node_type_name (JsonNode *node);
193 const gchar *json_node_type_name (JsonNode *node);
195 void json_node_set_object (JsonNode *node,
197 void json_node_take_object (JsonNode *node,
199 JsonObject * json_node_get_object (JsonNode *node);
200 JsonObject * json_node_dup_object (JsonNode *node);
201 void json_node_set_array (JsonNode *node,
203 void json_node_take_array (JsonNode *node,
205 JsonArray * json_node_get_array (JsonNode *node);
206 JsonArray * json_node_dup_array (JsonNode *node);
207 void json_node_set_value (JsonNode *node,
208 const GValue *value);
209 void json_node_get_value (JsonNode *node,
211 void json_node_set_string (JsonNode *node,
213 #if !GLIB_CHECK_VERSION(2,31,0)
214 G_CONST_RETURN gchar *json_node_get_string (JsonNode *node);
216 const gchar *json_node_get_string (JsonNode *node);
218 gchar * json_node_dup_string (JsonNode *node);
219 void json_node_set_int (JsonNode *node,
221 gint64 json_node_get_int (JsonNode *node);
222 void json_node_set_double (JsonNode *node,
224 gdouble json_node_get_double (JsonNode *node);
225 void json_node_set_boolean (JsonNode *node,
227 gboolean json_node_get_boolean (JsonNode *node);
228 gboolean json_node_is_null (JsonNode *node);
233 GType json_object_get_type (void) G_GNUC_CONST;
234 JsonObject * json_object_new (void);
235 JsonObject * json_object_ref (JsonObject *object);
236 void json_object_unref (JsonObject *object);
238 #ifndef JSON_DISABLE_DEPRECATED
239 void json_object_add_member (JsonObject *object,
240 const gchar *member_name,
241 JsonNode *node) G_GNUC_DEPRECATED;
242 #endif /* JSON_DISABLE_DEPRECATED */
244 void json_object_set_member (JsonObject *object,
245 const gchar *member_name,
247 void json_object_set_int_member (JsonObject *object,
248 const gchar *member_name,
250 void json_object_set_double_member (JsonObject *object,
251 const gchar *member_name,
253 void json_object_set_boolean_member (JsonObject *object,
254 const gchar *member_name,
256 void json_object_set_string_member (JsonObject *object,
257 const gchar *member_name,
259 void json_object_set_null_member (JsonObject *object,
260 const gchar *member_name);
261 void json_object_set_array_member (JsonObject *object,
262 const gchar *member_name,
264 void json_object_set_object_member (JsonObject *object,
265 const gchar *member_name,
267 GList * json_object_get_members (JsonObject *object);
268 JsonNode * json_object_get_member (JsonObject *object,
269 const gchar *member_name);
270 JsonNode * json_object_dup_member (JsonObject *object,
271 const gchar *member_name);
272 gint64 json_object_get_int_member (JsonObject *object,
273 const gchar *member_name);
274 gdouble json_object_get_double_member (JsonObject *object,
275 const gchar *member_name);
276 gboolean json_object_get_boolean_member (JsonObject *object,
277 const gchar *member_name);
278 #if !GLIB_CHECK_VERSION(2,31,0)
279 G_CONST_RETURN gchar *json_object_get_string_member (JsonObject *object,
280 const gchar *member_name);
282 const gchar *json_object_get_string_member (JsonObject *object,
283 const gchar *member_name);
285 gboolean json_object_get_null_member (JsonObject *object,
286 const gchar *member_name);
287 JsonArray * json_object_get_array_member (JsonObject *object,
288 const gchar *member_name);
289 JsonObject * json_object_get_object_member (JsonObject *object,
290 const gchar *member_name);
291 gboolean json_object_has_member (JsonObject *object,
292 const gchar *member_name);
293 void json_object_remove_member (JsonObject *object,
294 const gchar *member_name);
295 GList * json_object_get_values (JsonObject *object);
296 guint json_object_get_size (JsonObject *object);
297 void json_object_foreach_member (JsonObject *object,
298 JsonObjectForeach func,
301 GType json_array_get_type (void) G_GNUC_CONST;
302 JsonArray * json_array_new (void);
303 JsonArray * json_array_sized_new (guint n_elements);
304 JsonArray * json_array_ref (JsonArray *array);
305 void json_array_unref (JsonArray *array);
306 void json_array_add_element (JsonArray *array,
308 void json_array_add_int_element (JsonArray *array,
310 void json_array_add_double_element (JsonArray *array,
312 void json_array_add_boolean_element (JsonArray *array,
314 void json_array_add_string_element (JsonArray *array,
316 void json_array_add_null_element (JsonArray *array);
317 void json_array_add_array_element (JsonArray *array,
319 void json_array_add_object_element (JsonArray *array,
321 GList * json_array_get_elements (JsonArray *array);
322 JsonNode * json_array_get_element (JsonArray *array,
324 gint64 json_array_get_int_element (JsonArray *array,
326 gdouble json_array_get_double_element (JsonArray *array,
328 gboolean json_array_get_boolean_element (JsonArray *array,
330 #if !GLIB_CHECK_VERSION(2,31,0)
331 G_CONST_RETURN gchar *json_array_get_string_element (JsonArray *array,
334 const gchar *json_array_get_string_element (JsonArray *array,
337 gboolean json_array_get_null_element (JsonArray *array,
339 JsonArray * json_array_get_array_element (JsonArray *array,
341 JsonObject * json_array_get_object_element (JsonArray *array,
343 JsonNode * json_array_dup_element (JsonArray *array,
345 void json_array_remove_element (JsonArray *array,
347 guint json_array_get_length (JsonArray *array);
348 void json_array_foreach_element (JsonArray *array,
349 JsonArrayForeach func,
354 #endif /* __JSON_TYPES_H__ */