How strong is PropertyTree JSON support

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

How strong is PropertyTree JSON support

Boost - Users mailing list
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
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: How strong is PropertyTree JSON support

Boost - Users mailing list

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




From: Boost-users <[hidden email]> on behalf of Michael Powell via Boost-users <[hidden email]>
Sent: Tuesday, January 8, 2019 6:50:52 PM
To: [hidden email]
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
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: How strong is PropertyTree JSON support

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
On 1/8/19 6:50 PM, Michael Powell via Boost-users wrote:

> Thoughts? Suggestions?

https://github.com/breese/trial.protocol
http://breese.github.io/trial/protocol/trial_protocol/json.html
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [EXTERNAL] Re: How strong is PropertyTree JSON support

Boost - Users mailing list
In reply to this post by Boost - Users mailing list

You might also want to look at https://github.com/Tencent/rapidjson

It’s a little hard to use (restrictions put in to make it run crazy fast) but it’s almost impossible to use INCORRECTLY because the compiler won’t let you make most mistakes (violations of the restrictions) you would make.

 

From: Boost-users <[hidden email]> On Behalf Of Stian Zeljko Vrba via Boost-users
Sent: Tuesday, January 08, 2019 11:15 AM
To: [hidden email]
Cc: Stian Zeljko Vrba <[hidden email]>
Subject: [EXTERNAL] Re: [Boost-users] How strong is PropertyTree JSON support

 

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

 

 


From: Boost-users <[hidden email]> on behalf of Michael Powell via Boost-users <[hidden email]>
Sent: Tuesday, January 8, 2019 6:50:52 PM
To: [hidden email]
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
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: How strong is PropertyTree JSON support

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
On Tue, Jan 8, 2019 at 1:33 PM Bjorn Reese via Boost-users
<[hidden email]> wrote:
>
> On 1/8/19 6:50 PM, Michael Powell via Boost-users wrote:
>
> > Thoughts? Suggestions?
>
> https://github.com/breese/trial.protocol
> http://breese.github.io/trial/protocol/trial_protocol/json.html

I'm not sure, what am I supposed to be keying in on here? Looks like
straight usage of the PropertyTree Json support? Thanks, but I
gathered that already, and then some.

> _______________________________________________
> Boost-users mailing list
> [hidden email]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: How strong is PropertyTree JSON support

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
On 1/8/19 8:31 PM, Michael Powell via Boost-users wrote:

> I'm not sure, what am I supposed to be keying in on here? Looks like
> straight usage of the PropertyTree Json support? Thanks, but I
> gathered that already, and then some.

You concluded yourself that PropertyTree is probably not what your
are looking for. You received two responses about other JSON libraries
that you can use instead.

You could try to roll your own, but the simplicity of the JSON syntax
is deceiving. See for instance:

   http://seriot.ch/parsing_json.php

So you would be better of using a standards-compliant library.

The one I suggested has the advantage that you could use its low-level
API as a JSON lexer to build your own AST, or you could use the higher-
level tree structure that comes with the library.
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: How strong is PropertyTree JSON support

Boost - Users mailing list
On Tue, Jan 8, 2019 at 2:55 PM Bjorn Reese via Boost-users
<[hidden email]> wrote:

>
> On 1/8/19 8:31 PM, Michael Powell via Boost-users wrote:
>
> > I'm not sure, what am I supposed to be keying in on here? Looks like
> > straight usage of the PropertyTree Json support? Thanks, but I
> > gathered that already, and then some.
>
> You concluded yourself that PropertyTree is probably not what your
> are looking for. You received two responses about other JSON libraries
> that you can use instead.
>
> You could try to roll your own, but the simplicity of the JSON syntax
> is deceiving. See for instance:
>
>    http://seriot.ch/parsing_json.php

Thank you for that bit of clarification.

> So you would be better of using a standards-compliant library.
>
> The one I suggested has the advantage that you could use its low-level
> API as a JSON lexer to build your own AST, or you could use the higher-
> level tree structure that comes with the library.
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: How strong is PropertyTree JSON support

Boost - Users mailing list
In reply to this post by Boost - Users mailing list


On Wed, 9 Jan 2019 at 01:15, Stian Zeljko Vrba via Boost-users <[hidden email]> wrote:

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



I concur. After looking for a full implementation with a strong and useful interface I settled on this one.

The provision of _json and _json_pointer literals is a very nice touch. Also the ability to create JSON objects using initialiser lists allows the programmer to be almost as expressive as when writing javascript.

 



From: Boost-users <[hidden email]> on behalf of Michael Powell via Boost-users <[hidden email]>
Sent: Tuesday, January 8, 2019 6:50:52 PM
To: [hidden email]
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
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users


--
Richard Hodges
office: +442032898513
home: +376841522
mobile: +376380212 (this will be *expensive* outside Andorra!)
skype: madmongo
facebook: hodges.r


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