GNOME Bugzilla – Bug 773410
Add JCON, JSON C Object Notation
Last modified: 2017-09-05 10:42:31 UTC
Adding a bug here to track support for JCON. I'm going to attach patches for JCON support. I don't expect them to be committed as is, but figured I'd land things here as a place for us to collaborate on features and make progress. One thing I don't like about the current implementation is the difference of JCON_STRING() vs JCONE_STRING() (for all the data types). I think we can unify these macros and do the right thing based on the context of either creation (JCON_NEW) or extraction (JCON_EXTRACT). Feel free to iterate on the patches, or let me know and I can find some time to do it.
Created attachment 338327 [details] [review] build: bump for development version
Created attachment 338328 [details] [review] jcon: add "JavaScript C Object Notation" JCON provides a simplified interface to creating and parsing known JSON document schemas. This is performed using the combination of va_list and struct initializers. It is not necessarily as safe as the static typing we would get from imperative use of the JsonNode APIs, but it does provide a clarity of syntax in the source files that is more easily code reviewed. We might consider adding more stringent checks in the future based on common errors we see. For example, I anticipate the wrong use of JCON_STRING vs JCONE_STRING() depending on the context. There might be further opportunity to unify these two macros into a single that always takes a pointer to the target location, with one doing a read and one doing a write basedon JCON_NEW() vs JCON_EXTRACT(). See json-glib/tests/jcon.c for example usage.
I like it very much. It'll need to be updated to use Meson, now that we dropped autotools from master; it'll also need to be skipped from introspection. The main issue I see is that gtk-doc will likely choke on the namespace.
(In reply to Emmanuele Bassi (:ebassi) from comment #3) > The main issue I see is that gtk-doc will likely choke on the namespace. Indeed. For Jsonrpc-Glib, I ported the public API to GVariant (so I can avoid JSON parsing with known peers). So I had to port JCON to GVariant. In that form, I namespaced things like: JSONPRC_MESSAGE_NEW() JSONRPC_MESSAGE_PARSE() and the to clarify in/out directions: JSONRPC_MESSAGE_GET_STRING (&foostr) JSONRPC_MESSAGE_PUT_STRING (foostr) so that we get a modicum of type safety.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/json-glib/issues/18.