[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] Should we switch to a different JSON library?

On Tue, Nov 07, 2017 at 01:28:00PM +0000, Daniel P. Berrange wrote:
On Tue, Nov 07, 2017 at 02:05:25PM +0100, Martin Kletzander wrote:
Hi everyone,

so we are using yajl for parsing JSON.  However there are some reasons
why we might consider switching to another one:

 1) It is basically dead upstream

One could say that it is simply "feature complete" upstream so doesn't
need more work, but none the less, I have a general bad feeling about
relying on a library with no active maint work going on for best part
of 4 years, and 68 open pull requests.

 2) We're just using the lexer part of it
 3) We only use it for parsing

Aren't 2 & 3 the same point repeated ? Regardless though, we use yajl
for formatting JSON too (virJSONValueToString)

I meant 2 different things.  By only using the parser I meant that for
some reason (I guess the first implementation wasn't good enough, but
you'll be the one to know the proper one) we store it in our own object
for which we need to parse the data similarly to how SAX works, right?
We register callbacks and we do lot of stuff for each value found.  It
looks like jansson has enough APIs so that virJSON* could be just
trivial wrappers around json_* functions/structures and for example for
parsing we could just call json_load().  I haven't studied it
thoroughly, but that's the feeling I got.

The second thing was a bit of a misunderstanding on my part, we clearly
use it for formatting as well, yes.

 4) The are workarounds for it in the code

I don't recall what these are now ?

So I looked at some options and found few other libraries, I only took
those that are widely available (read: I checked if some random
downstream distro has them), however most of them were not very much
usable.  Except one.  But here's the list of few others that didn't look
that bad either.  All are MIT-licensed, try to be thread-safe and
support pkg-config:

- libfastjson [1] - from rsyslog community, optimized for working with
                    logs, used almost only by rsyslog, it's supposed to
                    have doxygen docs, they switched to libfastjson
                    from json-c due to some problems with it
                    (performance, ref counting bug, ...)

If its only used by 1 app, I would stay well clear of it, as that's just
one step away from be unused and dead.

- json-c [2] - looked abandoned until I looked at the proper github
               page, "documentation" in doxygen

Yeah, this is the main one I know about and existed way back when I
picked yajl originally.

It has plenty of apps using it in Fedora, which is good.

At first the header files look to have good namespacing, but then I
see horrific things like this polluting the namespaces:

 #undef FALSE
 #define FALSE ((json_bool)0)

 #undef TRUE
 #define TRUE ((json_bool)1)

 #define hexdigit(x) (((x) <= '9') ? (x) - '0' : ((x) & 7) + 9)
 #define error_ptr(error) ((void*)error)
 #define error_description(error)  (json_tokener_errors[error])
 #define is_error(ptr) (ptr == NULL)

- Jansson [3] - I really like this one.  The API seems very intuitive,
                it has nice documentation [4] in readthedocs (and I'm
                not talking about the visual style, but how easy is to
                find information), it can be used for formatting JSON
                in a similar way we are doing it.  It has json_auto_t
                (optional) type that uses the attribute cleanup for
                automatic scope dereference (just in case we want to
                use it), it has iterators... did I tell you I like this
                one a lot?

Like yajl did, they seem to have had an explicit ABI break at their 2.0
version, which was released in 2011. Not a big deal if we only support
their 2.x series, especially if we keep yajl as an optional fallback

It has 15 open PRs and 32 open bugs, but unlike yajl it actually has
active development taking place

Its header namespace looks clean too.

What do you (others) think of switching the JSON library?  Do you know
about any other projects that could be used considering license,
platform support, etc.?  Also feel free to fix any mistakes I might have
posted.  I double-checked it, but you know, "trust, but verify".

I'd be broadly in favour of switching to something that is not dead :-)

I agree that Jansson appears the most promising.

I think we would have to keep yajl support in parallel, but that's not
too hard, since this is all isolated in virjson.c

Sure, I guess we would just have 2 implementations like we used to have
with threads, selecting particular one at compile-time.

|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

Attachment: signature.asc
Description: Digital signature

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]