summaryrefslogtreecommitdiff
path: root/json-glib/json-types.h
Commit message (Collapse)AuthorAgeFilesLines
* Update the node documentationEmmanuele Bassi2021-06-101-22/+22
|
* docs: Initial, rough port away from gtk-docEmmanuele Bassi2021-06-081-32/+20
| | | | | | | | | | Drop `SECTION` blurbs. Use gi-docgen syntax for internal links. Use summary lines for gi-docgen indices. Use Markdown syntax for code fragments.
* Add ordered iterator for JsonObjectEmmanuele Bassi2020-08-241-0/+8
| | | | | | | | | The current iterator API does not guarantee the iteration order, as it's based off of the hash table iterator. JsonObject, though, can guarantee the iteration order—we do that for json_object_foreach_member(). Instead of changing the behaviour of json_object_iter_next(), we can add API to initialize and iterate a JsonObjectIter in insertion order.
* Merge branch 'get-with-default' into 'master'Emmanuele Bassi2017-12-151-11/+27
|\ | | | | | | | | | | | | Add JsonObject getters with fallback value Closes #4 See merge request GNOME/json-glib!4
| * Add with_default() variant for JsonObject gettersEmmanuele Bassi2017-11-141-11/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When using the typed getters for JsonObject, the existing API will automatically fail if the member requested is not present. This is generally good practice, because JSON data typically does not have a schema, and thus is has to be validated "on the go"; a JSON object member that contains `null`, or `0`, or `false`, is indistinguishable from a JSON object member that does not exist, so we cannot simply return a scalar value and be done with it. We can provide an escape hatch, though, for the crowd writing parsers for JSON data; by using Python as the model, we can add methods that take a default value as a parameter, and return it as a fallback value if the requested object member does not exist, or if it's set to `null`.
* | node: Use json_node_unref for the JsonNode autoptr cleanupRobert Ancell2017-12-061-1/+1
|/ | | | | | json_node_unref was added after the autoptr macros were written. This fixes an assertion failure if using autoptr and json_node_ref.
* json-types.h: Add missing JSON_AVAILABLE_IN_1_2Chun-wei Fan2016-04-191-0/+1
| | | | | The json_node_is_immutable() missed an JSON_AVAILABLE_IN_1_2, causing it not to be exported. Fix this.
* fixup! docs: Fix the Since tagsEmmanuele Bassi2016-03-011-1/+1
|
* core: Add JSON node, object, array hashesPhilip Withnall2016-03-011-0/+27
| | | | | | | | | | | | | | | | | | | Now that these objects can be marked as immutable, it is possible to calculate and cache hash values for each of them. This allows efficient hash-based deduplication of large numbers of JSON nodes, as needed by Walbottle for JSON test vector generation. To complement the new hash functions, each of JsonNode, JsonValue, JsonObject and JsonArray also now have an equal() comparison method. This compares them structurally and recursively, using the definition of equality from the JSON Schema specification, which seems as good as any other. http://json-schema.org/latest/json-schema-core.html#anchor9 https://bugzilla.gnome.org/show_bug.cgi?id=756121 Signed-off-by: Emmanuele Bassi <ebassi@gnome.org>
* node: Add json_node_ref() and json_node_unref()Philip Withnall2016-03-011-0/+5
| | | | | | | | | | | | | | Add reference counting semantics to JsonNode, in addition to the existing init/unset and alloc/free semantics. json_node_free() must only be used with nodes allocated using json_node_alloc(). json_node_unref() may be used with all nodes (if correctly paired; it may be paired with json_node_alloc()). It is not valid to call json_node_free() on a node whose reference count is not 1. https://bugzilla.gnome.org/show_bug.cgi?id=756121
* core: Add immutability support to core objectsPhilip Withnall2016-03-011-0/+13
| | | | | | | | | | | Add an immutable mode to JsonNode, JsonObject, JsonArray and JsonValue. This is an optional mode which objects enter by calling json_*_seal(). It is a one-way transition, which means that we can build and manipulate objects as much as desired, before sealing them and enjoying the benefits of immutable objects: no need to take copies when handling them, persistent hash values (still to be implemented). https://bugzilla.gnome.org/show_bug.cgi?id=756121
* Add autoptr macrosEmmanuele Bassi2016-02-291-0/+6
| | | | | | | GLib can take advantage of the "cleanup" attribute by using a bunch of macro magic. This has been slowly been used across various libraries in the G* stack, so JSON-GLib should provide symbols for the automatic memory management of its types.
* types: Tweak dummy padding in JsonObjectIterPhilip Withnall2015-11-061-2/+4
| | | | | | | | | Use padding which resembles the ABI structure of GHashTableIter so that our struct size is the same as GHashTableIter on all platforms, rather than just on x86_64. This fixes the static assertion failure on i386 and armhf. https://bugzilla.gnome.org/show_bug.cgi?id=757675
* object: Add JsonObjectIter to ease iteration over JsonObject membersPhilip Withnall2015-10-061-0/+26
| | | | | | | | | | This is a stack-allocated iterator object similar to GHashTableIter which allows allocation-free iteration over the members in a JsonObject. It differs from json_object_foreach_member() in the order in which it iterates — for JsonObjectIter the order is undefined. https://bugzilla.gnome.org/show_bug.cgi?id=755509
* Use compiler annotations to determine symbol visibilityEmmanuele Bassi2014-03-181-9/+94
| | | | | | | | | | | | | | | | | Instead of relying on a separate file that requires being update every time we add a new public function we should use compiler annotations to let the linker know which symbols are public and exported. In order to achieve this we have to: * check for the visibility=hidden attribute * add -fvisibility=hidden to the linker flags * add a macro to annotate all public symbols While we're at it, we should copy the versioned symbols macro layout already used by GLib, GTK+, and other G* libraries, including the ability to express the range of allowed versions of JSON-GLib that third party code can compile against.
* Move the single include guard after multiple inclusion oneEmmanuele Bassi2013-12-041-3/+3
| | | | | | | | | | | | | | GCC (and other compilers) can optimise multiple inclusion of headers if they find the: #ifndef FOO #define FOO #endif pattern as the first thing inside a header. The single-header inclusion guard was preventing that from happening, so we need to move it inside the multiple inclusion guard.
* node: Add typed initializersEmmanuele Bassi2012-10-271-0/+19
| | | | | | | | | | | We should simplify the JsonNode API a bit, especially when it comes to initializing nodes. Instead of a two-step "new(<type>) followed by a set_<type>(value)" API, we can provide a "init_<type>(value)" API that can take any existing JsonNode and initialize it to the given type. This makes the JsonNode creation more concise and reliable; it also allows to implicitly re-initialize JsonNodes without requiring the user to de-allocate/re-allocate them first.
* Remove JSON_DISABLE_DEPRECATEDEmmanuele Bassi2012-01-141-2/+0
| | | | We have deprecations warnings from the compiler, now.
* Bump up the GLib dependencyEmmanuele Bassi2011-10-171-6/+0
| | | | It's the development cycle, we can start using GLib 2.31.
* Use the new GLib deprecation schemeEmmanuele Bassi2011-10-171-2/+17
| | | | | Instead of using a defined symbol to remove the deprecated functions from the library, we should use compiler warnings.
* Remove G_CONST_RETURN usageEmmanuele Bassi2011-06-091-4/+4
| | | | | | | | See GLib bug: https://bugzilla.gnome.org/show_bug.cgi?id=644611 The macro is going to be deprecated soon.
* docs: Remove unused field annotationEmmanuele Bassi2010-05-281-1/+0
| | | | JsonNode is fully opaque, so there are no fields to annotate.
* [node] Add HOLDS macros for quick type checkingEmmanuele Bassi2009-09-281-0/+51
| | | | JsonNode should mimick GValue's API and have macros for easy type checking
* [node] Add JsonNode.set_parent()Emmanuele Bassi2009-09-061-0/+2
| | | | | Add the setter for JsonNode:parent, to be used in JsonParser instead of directly accessing the JsonNode structure.
* Disallow single header file inclusionEmmanuele Bassi2009-08-121-0/+4
| | | | | | | | | The correct header file for JSON-GLib is, and has always been, json-glib.h. Anything else was not supported, as we've been moving around stuff for a while, now. This commit enforces the single include file, using the same policy enacted by other libraries, like: GLib, GTK+ and Clutter.
* Auto-promote integer types to G_TYPE_INT64Emmanuele Bassi2009-08-121-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The JSON RFC does not specify the size of the integer type, thus implicitly falling back to machine-size. This would all be fine and dandy if some demented Web Developer (and I use the term "developer" *very much* loosely) did not decide to use integers to store unique identifiers for objects; obviously, you can't have more than 2^32-1 status messages in a database with millions of users who update their status multiple times per day. Right, Twitter? Anyway, some languages do a type auto-promotion from Integer to Long, thus pushing the limit of allowed positive values -- until the next integer overflow, that is. C, and GLib, do not do that transparently for us so we need to: - always use gint64 when parsing a JSON data stream using JsonScanner - move all the Node, Object and Array APIs to gint64 - auto-promote G_TYPE_INT to G_TYPE_INT64 when setting a GValue manually - auto-promote and auto-demote G_TYPE_INT properties when (de)serializing GObjects. The GLib types used internally by JSON-GLib are, thus: integer -> G_TYPE_INT64 boolean -> G_TYPE_BOOLEAN float -> G_TYPE_DOUBLE string -> G_TYPE_STRING
* [node] Make JsonNode completely privateEmmanuele Bassi2009-06-091-24/+14
| | | | | | | | | | The JsonNode structure has always been meant to be completely opaque; we indirectly exposed the :type member, but only for access through the JSON_NODE_TYPE() macro. Since that macro has become a proxy for the json_node_get_node_type() function we can safely move everything into a private, uninstalled header file and let JsonNode be completely opaque to the developer.
* Add JsonArray iteration functionEmmanuele Bassi2009-05-171-0/+21
| | | | | | Similarly to commit 3057a172 for JsonObject, the newly added json_array_foreach_element() iterates over a JSON array data type.
* Add JsonObject iteration functionEmmanuele Bassi2009-05-161-2/+23
| | | | | The json_object_foreach_member() function iterates over a JsonObject data type.
* [node] Add is_null() methodEmmanuele Bassi2009-04-171-0/+1
| | | | | The json_node_is_null() function is just a quick check for nodes set to null.
* [node] Make JSON_NODE_TYPE call a functionEmmanuele Bassi2009-04-171-1/+1
| | | | | | | | Second pass at adding type safety to the JsonNode type checks. The JSON_NODE_TYPE macro now calls the json_node_get_node_type() function which hides the JsonNode.type structure field and gives us a little bit more of future compatibility.
* [node] Add function version of JSON_NODE_TYPE macroEmmanuele Bassi2009-04-171-2/+3
| | | | | First pass at adding some type safety to the JsonNode type checks, and at removing every mention of the JsonNode interna fields.
* Add convenience accessors to JsonArrayEmmanuele Bassi2009-04-171-15/+42
| | | | | | | | | | Like commit 5bb6ea91 did for JsonObject, we should add typed convenience accessors to JsonArray in order to cut down the amount of nodes needed when parsing and generating JSON data streams. As for JsonObject, the amount of types is small enough to avoid the combinatorial API explosion.
* Deprecate add_member() and add set_member() and friendsEmmanuele Bassi2009-04-171-18/+65
| | | | | | | | | | | | | | | | | | | The add_member() method of JsonObject has wee bit weird semantics: if the member to be added already exists it prints a scary warning and returns - and yet it calls g_hash_table_replace() internally as if it overwrites the member. So, instead of changing semantics midway we can: - add a json_object_set_member() which adds a new member and overwrites existing members - deprecate json_object_add_member() While we're at it, we can add convenience wrappers for set_member() and get_member() that don't require us toying with nodes; luckily, since the amount of valid types we can add to a JsonObject is limited, this does not lead to a combinatorial API explosion.
* Add API to retrieve copies of the nodes inside objects and arraysEmmanuele Bassi2007-11-211-0/+4
| | | | | | Getting copies of the nodes might work better for high level languages binding the JSON-GLib API, because they can manage the lifetime of the returned values using their own rules.
* Add a GType for JsonNodeEmmanuele Bassi2007-11-131-2/+6
| | | | | | We need a GType for nodes if we want to add JsonNode properties or signal marshallers to a GObject class. We could use pointers, but we'd loose type safety, so it's a no-no.
* Add the JsonSerializable interfaceEmmanuele Bassi2007-10-161-0/+1
| | | | | | | The JsonSerializable interface allows implementations to override the GObject-to-JSON serialization process, by providing two virtual methods to control the (de)serialization of GObject properties. This way it's possible to serialize GObjects with properties holding complex data types.
* Add a method for getting all the nodes from a JsonObjectEmmanuele Bassi2007-10-161-0/+1
| | | | | To map json_array_get_elements(), a json_object_get_values() method has been added which returns the list of JsonNodes contained by a JsonObject.
* Add API for removing nodes from arrays and objectsEmmanuele Bassi2007-10-151-61/+65
| | | | | | | Write and document json_object_remove_member() and json_array_remove_element() which can be used to remove a JsonNode from a JsonObject or a JsonArray respectively. This way, the JsonObject and JsonArray are API-complete and the object model can be manipulated in code.
* Add json_node_dup_string()Emmanuele Bassi2007-10-081-0/+1
| | | | | The newly added json_node_dup_string() is a convenience function for getting a copy of the string contained inside a JsonNode.
* Add convenience accessors for fundamental types in JsonNodeEmmanuele Bassi2007-10-051-0/+12
| | | | | | This commit adds some convenience accessors for setting and getting fundamental types in and from a JsonNode, to avoid jumping through all the GValue hoops.
* Implement the GType functions for JsonObject and JsonArrayEmmanuele Bassi2007-10-051-2/+2
| | | | | | | | | | The type functions for the JsonObject and JsonArray types were declared, albeit with the wrong return value, but not implemented. This commit fixed the return value and implements them. JsonObject and JsonArray are boxed types because we don't need them to be GObjects (no signals, no inheritance and their implementation must be completely opaque for the developer).
* Document the new public functionsEmmanuele Bassi2007-10-011-0/+2
| | | | | Now that we moved the constructors and setters for the JSON data types into the public symbols we need to document them to get back to 100% doc coverage.
* Move data types ctors and setters into the public headersEmmanuele Bassi2007-10-011-7/+31
| | | | | | | Now that we are providing a generator class we need to provide the constructors and setters for JsonNode, JsonObject and JsonArray. This also means that the json-private.h header is now useless, so we can remove it from the build and repository.
* Complete API reference of JSON-GLibEmmanuele Bassi2007-10-011-0/+20
| | | | With this commit, we reach 100% coverage.
* Add licensing informations to the source codeEmmanuele Bassi2007-10-011-0/+35
|
* Add JsonNode, a generic container for JSON typesEmmanuele Bassi2007-10-011-25/+34
| | | | | | | | | | | | | | | | | This huge commit removes JsonData and adds JsonNode, the generic container for fundamental and complex data types extracted from a JSON stream. The contents of a JsonNode can be extracted from it in form of a GValue for fundamental types (integers, floats, strings, booleans) or in form of JsonObject and JsonArray objects. JsonObject and JsonArray now accept JsonNodes instead of GValues. The JsonParser object builds the data model tree when parsing a JSON stream; the tree can be recursed by getting the root node and walking it using the GValue API for the fundamental types and the objects/arrays API for complex types. The API has been updated and the tests now recurse through the generated data model tree.
* Add JsonData, an opaque container for JSON data typesEmmanuele Bassi2007-09-211-16/+37
| | | | | | | JsonData is like GValue, but it stores JSON data types (objects and arrays) and allows us to retrieve them safely. This way we can actually know the type of the objects returned by the parser and by the other object walking functions.
* Initial import of JSON-GLibEmmanuele Bassi2007-09-201-0/+32
JSON-GLib is a JSON parser library written with GLib and GObject. JSON is the JavaScript Object Notation, and it's used to define objects and object hierarchies in a human-readable way.