Boost logo

Boost Users :

Subject: Re: [Boost-users] How strong is PropertyTree JSON support
From: Stian Zeljko Vrba (vrba_at_[hidden])
Date: 2019-01-08 18:14:46


You might want to take a look at https://github.com/nlohmann/json

________________________________
From: Boost-users <boost-users-bounces_at_[hidden]> on behalf of Michael Powell via Boost-users <boost-users_at_[hidden]>
Sent: Tuesday, January 8, 2019 6:50:52 PM
To: boost-users_at_[hidden]
Cc: Michael Powell
Subject: [Boost-users] How strong is PropertyTree JSON support

Hello,

I have a requirement to support parsing JSON, and while I could
potentially pull together a Spirit Qi (or even X3, possibly) based
grammar, I wonder with all the idiosyncrasies, i.e. particularly
strings, escape sequences, Unicode, etc, is it worth it.

Then there's the Boost.PropertyTree JSON support, which I think may be
an adequate fit. However, just how robust is this support when it
comes to handling some of the nuanced corner cases? The harder ones I
think are the potential for escape sequences, Unicode, etc, embedded
within a String.

i.e. https://json.org/
or, http://es5.github.io/x7.html

It seems with Property Tree there are also these limitations:

<docs>
The property tree dataset is not typed, and does not support arrays as
such. Thus, the following JSON / property tree mapping is used:

* JSON objects are mapped to nodes. Each property is a child node.
* JSON arrays are mapped to nodes. Each element is a child node with
an empty name. If a node has both named and unnamed child nodes, it
cannot be mapped to a JSON representation.
* JSON values are mapped to nodes containing the value. However, all
type information is lost; numbers, as well as the literals "null",
"true" and "false" are simply mapped to their string form.
* Property tree nodes containing both child nodes and data cannot be mapped.
</docs>

It seems to me that much of the limitation is in adapting the
PropertyTree to the JSON structure, but mostly vice versa. Not quite
fitting a square peg in a round hole, but coming quite close, I think:

"If a node has both named and unnamed child nodes, it cannot be mapped
to a JSON representation." We're talking about the mapping from
PropertyTree to JSON here?

Seems like a potentially problematic issue depending on desired usage,
'all type information is lost; numbers, as well as the literals
"null", "true" and "false" are simply mapped to their string form'.

I'm not sure what "nodes containing both child nodes and data" means?

https://www.boost.org/doc/libs/1_69_0/doc/html/property_tree/parsers.html#property_tree.parsers.json_parser

Besides these concerns, I should think a grammar is fairly
straightforward to construct, if push came to shove. It's either
living with the Boost.PropertyTree or rolling my own AST, which is not
outside the realm of possibility for my purposes.

Thoughts? Suggestions?

Thanks!

Michael Powell
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
https://lists.boost.org/mailman/listinfo.cgi/boost-users



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net