Boost logo

Boost :

Subject: Re: [boost] Interest in a Boost.JSON library?
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2008-12-21 06:36:23

On Sun, Dec 21, 2008 at 3:49 AM, Kirit Sælensminde
<kirit.saelensminde_at_[hidden]> wrote:
> Boris wrote:
>> On Sun, 21 Dec 2008 08:51:37 +0100, Kirit Sælensminde
>> <kirit.saelensminde_at_[hidden]> wrote:
>>> As part of our web application framework (currently being ported from
>>> Windows to Linux) we have a JSON parser and library that might be of
>>> interest to a wider community as part of the Boost libraries.
>> The JSON file format is supported by the Boost.PropertyTree library (see
>> at While I use this
>> library for quite some time I don't remember anymore if it has already been
>> accepted or if it's still waiting for a review to be accepted.
> Judging by the documentation[1] the parser seems to target a different use
> case. Mine includes a full JSON object, rather than the only partially
> compatible property tree -- for example, mine won't lose null, true or
> false type information (so can write back out the exact equivalent JSON
> after it has been parsed).
> I didn't see anything for how the Boost.PropertyTree implementation dealt
> with Unicode either -- I guess it just makes use of narrow characters, but I
> couldn't check as the implementation isn't there. Mine has a Spirit based
> parser which makes the parser itself usable directly in other parsers much
> more easily.
> The Boost.PropertyTree implementation is probably fine for the use that
> Boost.PropertyTree has, but it means that it doesn't really cover lots of
> use cases where you actually need to process JSON.
> [1]

Interesting timing. If you have been watching the spirit lists, a few
days ago I created a JSON parser in Spirit2x to both test for the vast
speed enhancements of Spirit2x and to donate as an example. Mine is
templated on the string and allows you to override the character class
parsing with any Spirit supported type (which does not include Unicode
yet, but will include it later, we have been talking about it, but
does currently support wide_chars).

One question, you have int64_t as a supported type, but from my
research the Number type in the current JSON spec is a 52/12-bit
floating-point type, double in other words. Mine is basic, a single
header file, and it stuffs it all into a Value type, which is a
Boost.Variant of a null_type, false_type, true_type (empty structs I
made, those are specified as types in the JSON standard, not bool's
for the true/false), double, StringType (whatever the templated String
type is), Object (an boost::unordered_map since the JSON standard
stats that it is an unordered map), and Array (which is just an
std::vector). All the types are not used in any special way and just
changing their declaration should keep compatibility with the rest of
the code. My code just returns the Value directly, not fancy wrapper
for pulling things out, but I left that open, would just require a one
line change of code to wrap it, but figured I might just do open
functions instead, allowing for a class style wrapper later, that way
it could be exported in a C style as well.

I did not make mine to be a 'real' library though, as stated, just an
example code, but I did try to make it as accurate to the spec as I

As soon as karma is finished for Spirit2x I was planning to make a
writer for my Value object as well, both as a condensed (efficient)
printer and a pretty printer.

As for comments, in my version it would be simple to change, the
whitespace skipping parser could easily be extended to catch other
things, such as comments, which would always be saved out. As stated,
was just making it as an example of the magic of Spirit2x.

Boost list run by bdawes at, gregod at, cpdaniel at, john at