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 ())
101 * A generic container of JSON data types. The contents of the #JsonNode
102 * structure are private and should only be accessed via the provided
103 * functions and never directly.
105 typedef struct _JsonNode JsonNode;
110 * A JSON object type. The contents of the #JsonObject structure are private
111 * and should only be accessed by the provided API
113 typedef struct _JsonObject JsonObject;
118 * A JSON array type. The contents of the #JsonArray structure are private
119 * and should only be accessed by the provided API
121 typedef struct _JsonArray JsonArray;
125 * @JSON_NODE_OBJECT: The node contains a #JsonObject
126 * @JSON_NODE_ARRAY: The node contains a #JsonArray
127 * @JSON_NODE_VALUE: The node contains a fundamental type
128 * @JSON_NODE_NULL: Special type, for nodes containing null
130 * Indicates the content of a #JsonNode.
141 * @object: the iterated #JsonObject
142 * @member_name: the name of the member
143 * @member_node: a #JsonNode containing the @member_name value
144 * @user_data: data passed to the function
146 * The function to be passed to json_object_foreach_member(). You
147 * should not add or remove members to and from @object within
148 * this function. It is safe to change the value of @member_node.
152 typedef void (* JsonObjectForeach) (JsonObject *object,
153 const gchar *member_name,
154 JsonNode *member_node,
159 * @array: the iterated #JsonArray
160 * @index_: the index of the element
161 * @element_node: a #JsonNode containing the value at @index_
162 * @user_data: data passed to the function
164 * The function to be passed to json_array_foreach_element(). You
165 * should not add or remove elements to and from @array within
166 * this function. It is safe to change the value of @element_node.
170 typedef void (* JsonArrayForeach) (JsonArray *array,
172 JsonNode *element_node,
178 GType json_node_get_type (void) G_GNUC_CONST;
179 JsonNode * json_node_new (JsonNodeType type);
180 JsonNode * json_node_copy (JsonNode *node);
181 void json_node_free (JsonNode *node);
182 JsonNodeType json_node_get_node_type (JsonNode *node);
183 GType json_node_get_value_type (JsonNode *node);
184 void json_node_set_parent (JsonNode *node,
186 JsonNode * json_node_get_parent (JsonNode *node);
187 const gchar * json_node_type_name (JsonNode *node);
189 void json_node_set_object (JsonNode *node,
191 void json_node_take_object (JsonNode *node,
193 JsonObject * json_node_get_object (JsonNode *node);
194 JsonObject * json_node_dup_object (JsonNode *node);
195 void json_node_set_array (JsonNode *node,
197 void json_node_take_array (JsonNode *node,
199 JsonArray * json_node_get_array (JsonNode *node);
200 JsonArray * json_node_dup_array (JsonNode *node);
201 void json_node_set_value (JsonNode *node,
202 const GValue *value);
203 void json_node_get_value (JsonNode *node,
205 void json_node_set_string (JsonNode *node,
207 const gchar * json_node_get_string (JsonNode *node);
208 gchar * json_node_dup_string (JsonNode *node);
209 void json_node_set_int (JsonNode *node,
211 gint64 json_node_get_int (JsonNode *node);
212 void json_node_set_double (JsonNode *node,
214 gdouble json_node_get_double (JsonNode *node);
215 void json_node_set_boolean (JsonNode *node,
217 gboolean json_node_get_boolean (JsonNode *node);
218 gboolean json_node_is_null (JsonNode *node);
223 GType json_object_get_type (void) G_GNUC_CONST;
224 JsonObject * json_object_new (void);
225 JsonObject * json_object_ref (JsonObject *object);
226 void json_object_unref (JsonObject *object);
228 #ifndef JSON_DISABLE_DEPRECATED
229 void json_object_add_member (JsonObject *object,
230 const gchar *member_name,
231 JsonNode *node) G_GNUC_DEPRECATED;
232 #endif /* JSON_DISABLE_DEPRECATED */
234 void json_object_set_member (JsonObject *object,
235 const gchar *member_name,
237 void json_object_set_int_member (JsonObject *object,
238 const gchar *member_name,
240 void json_object_set_double_member (JsonObject *object,
241 const gchar *member_name,
243 void json_object_set_boolean_member (JsonObject *object,
244 const gchar *member_name,
246 void json_object_set_string_member (JsonObject *object,
247 const gchar *member_name,
249 void json_object_set_null_member (JsonObject *object,
250 const gchar *member_name);
251 void json_object_set_array_member (JsonObject *object,
252 const gchar *member_name,
254 void json_object_set_object_member (JsonObject *object,
255 const gchar *member_name,
257 GList * json_object_get_members (JsonObject *object);
258 JsonNode * json_object_get_member (JsonObject *object,
259 const gchar *member_name);
260 JsonNode * json_object_dup_member (JsonObject *object,
261 const gchar *member_name);
262 gint64 json_object_get_int_member (JsonObject *object,
263 const gchar *member_name);
264 gdouble json_object_get_double_member (JsonObject *object,
265 const gchar *member_name);
266 gboolean json_object_get_boolean_member (JsonObject *object,
267 const gchar *member_name);
268 const gchar * json_object_get_string_member (JsonObject *object,
269 const gchar *member_name);
270 gboolean json_object_get_null_member (JsonObject *object,
271 const gchar *member_name);
272 JsonArray * json_object_get_array_member (JsonObject *object,
273 const gchar *member_name);
274 JsonObject * json_object_get_object_member (JsonObject *object,
275 const gchar *member_name);
276 gboolean json_object_has_member (JsonObject *object,
277 const gchar *member_name);
278 void json_object_remove_member (JsonObject *object,
279 const gchar *member_name);
280 GList * json_object_get_values (JsonObject *object);
281 guint json_object_get_size (JsonObject *object);
282 void json_object_foreach_member (JsonObject *object,
283 JsonObjectForeach func,
286 GType json_array_get_type (void) G_GNUC_CONST;
287 JsonArray * json_array_new (void);
288 JsonArray * json_array_sized_new (guint n_elements);
289 JsonArray * json_array_ref (JsonArray *array);
290 void json_array_unref (JsonArray *array);
291 void json_array_add_element (JsonArray *array,
293 void json_array_add_int_element (JsonArray *array,
295 void json_array_add_double_element (JsonArray *array,
297 void json_array_add_boolean_element (JsonArray *array,
299 void json_array_add_string_element (JsonArray *array,
301 void json_array_add_null_element (JsonArray *array);
302 void json_array_add_array_element (JsonArray *array,
304 void json_array_add_object_element (JsonArray *array,
306 GList * json_array_get_elements (JsonArray *array);
307 JsonNode * json_array_get_element (JsonArray *array,
309 gint64 json_array_get_int_element (JsonArray *array,
311 gdouble json_array_get_double_element (JsonArray *array,
313 gboolean json_array_get_boolean_element (JsonArray *array,
315 const gchar * json_array_get_string_element (JsonArray *array,
317 gboolean json_array_get_null_element (JsonArray *array,
319 JsonArray * json_array_get_array_element (JsonArray *array,
321 JsonObject * json_array_get_object_element (JsonArray *array,
323 JsonNode * json_array_dup_element (JsonArray *array,
325 void json_array_remove_element (JsonArray *array,
327 guint json_array_get_length (JsonArray *array);
328 void json_array_foreach_element (JsonArray *array,
329 JsonArrayForeach func,
334 #endif /* __JSON_TYPES_H__ */