| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
|
|
|
| |
Drop `SECTION` blurbs.
Use gi-docgen syntax for internal links.
Use summary lines for gi-docgen indices.
Use Markdown syntax for code fragments.
|
|
|
|
|
|
|
| |
We document that it's not safe, but we kind of rely on GHashTable to do
that for us. Instead, let's use the newly added age field to protect
against accidental mutations during iteration, just like we do for the
iterator API.
|
|
|
|
|
| |
The iteration order is the insertion order, and has been for a long
time.
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
It is an error to use the following with a missing member:
• json_object_get_int_member
• json_object_get_double_member
• json_object_get_boolean_member
• json_object_get_null_member
• json_object_get_string_member
• json_object_get_array_member
• json_object_get_object_member
Doing so will lead to CRITICALs like these:
Json-CRITICAL **: json_object_get_string_member: assertion
'node != NULL' failed
Instead one of these should be used to determine the existence of the
member:
• json_object_get_member
• json_object_has_member
Or, when available, one can use the corresponding
json_object_get_<type>_member_with_default.
https://gitlab.gnome.org/GNOME/json-glib/issues/24
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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`.
|
|
|
|
|
|
|
| |
Use JsonObject's private members_ordered
GQueue instead. This avoids a g_list_copy().
https://bugzilla.gnome.org/show_bug.cgi?id=773504
|
|
|
|
|
|
|
|
| |
This makes the list always ordered
and removes the g_list_reverse()
in json_object_get_members().
https://bugzilla.gnome.org/show_bug.cgi?id=773504
|
|
|
|
|
|
|
|
|
| |
If a JsonObject has no members, json_object_get_members() and
json_object_get_values() will return NULL, so this commit makes that
behavior clear in the docs. It also adds the (nullable) annotation in a
few places in the same file.
https://bugzilla.gnome.org/show_bug.cgi?id=769206
|
|
|
|
| |
The newly added API is available since 1.2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
| |
They are not needed — json-glib is not at all thread safe.
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
| |
Clarify the documentation for json_node_set_object() and
json_object_get_array_member().
https://bugzilla.gnome.org/show_bug.cgi?id=754384
|
|
|
|
| |
All the platforms and build system we support have a config.h header.
|
|
|
|
|
| |
Drop the DocBook documentation, and move everything to the MarkDown
format used by modern gtk-doc.
|
|
|
|
|
| |
JsonNode, JsonObject, and JsonArray have various constructors, so we
need to annotate them.
|
|
|
|
|
| |
The typed setters in JsonArray and JsonObject should use the JsonNode
typed initializers.
|
|
|
|
|
|
| |
A null value is not only valid for JSON_NODE_NULL nodes, but also for
JSON_NODE_ARRAY and JSON_NODE_OBJECT nodes that do not have a JsonArray
or a JsonObject set.
|
|
|
|
| |
https://bugzilla.gnome.org/show_bug.cgi?id=660893
|
|
|
|
|
|
|
|
| |
See GLib bug:
https://bugzilla.gnome.org/show_bug.cgi?id=644611
The macro is going to be deprecated soon.
|
|
|
|
|
| |
The newly added g_atomic_int_dec_and_test() simplified the logic for
unreffing Object and Array.
|
|
|
|
| |
Instead of manual iteration, let's use the function GList provides us.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
When calling g_hash_table_replace() we also free the string holding the
member name. This means that the const gchar* pointer we store inside
the list of ordered member names now points to garbage - so if somebody
tries to iterate over the members list it will get random values instead
of a valid C string.
Since we guaranteed insertion order, if we replace the contents of a
JsonObject member we need to find the right pointer and replace it: just
removing and prepending won't do.
https://bugzilla.gnome.org/show_bug.cgi?id=642383
|
|
|
|
| |
Check if we're setting the same node, to avoid a needless replace.
|
|
|
|
| |
https://bugzilla.gnome.org/show_bug.cgi?id=638932
|
| |
|
| |
|
|
|
|
|
| |
We should not warn when asking for a string, array or object if the
contents were 'null'.
|
|
|
|
|
| |
We create JsonObject structures using g_slice_new(), so we need to
initialize every member of the structure ourselves.
|
|
|
|
|
|
|
| |
• Fix the transfer rules for JsonNode, JsonObject and JsonArray
getters.
• Annotate the methods returning lists
|
|
|
|
|
|
|
|
|
| |
Since we return the member names in insertion order, we should also
return the member values in the same order.
This also allows us to get rid of the (yucky) internal copies of
g_hash_table_get_keys() and g_hash_table_get_values(), since we use
the hash table only for storage and lookup purposes.
|
|
|
|
|
|
|
|
|
|
| |
When iterating over the members of a JsonObject, or when retrieving
the list of members, the insertion order should be preserved by the
JsonObject. This is simply implemented by keeping a mirror list of
the member names.
Apparently, though JSON does not guarantee any ordering, it is somewhat
expected by JSON (and ECMAScript) users.
|
|
|
|
|
| |
The normalization of member names inside JsonObject was removed by
commit 8a7e0f381dc7e49745680df92ebb428f18bf4832.
|
|
|
|
|
|
|
|
|
|
|
| |
JsonObject sanitizes the name of the member to replace all
characters defined by G_STR_DELIMITERS with '_'. This is
absolutely brain damaged, since a member name can be any
valid JSON string.
Obviously, if a member name maps to a GObject property is
entirely up to the GObject code to decide whether to sanitize
the member name or not.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
| |
The passed value is a pointer to a JsonObject, not to a JsonArray.
|
|
|
|
|
|
| |
json_object_set_object_member
Reviewed by Emmanuele Bassi
|
|
|
|
|
|
|
|
| |
THere is no such thing as the "Lesser General Public License
version 2": the LGPL v2 is the "Library GPL", and has been
superceded by v2.1 with the new "Lesser GPL" name.
Also, the copyright is now Intel Corp.
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
The json_object_foreach_member() function iterates over a JsonObject
data type.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
The json_object_has_member() used the passed in member name, instead of
the correctly normalized one.
|
|
|
|
|
| |
Including the autotools generated config.h should always be conditional
on the HAVE_CONFIG_H definitions.
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
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.
|