I think I would be in flavor of keeping it in a 3rd party library. There are so many trade offs for different problem types and requirements.
Do you require an Input Iterator, Forward, or Random. Each have a cost/benefit. With input you can pull straight from a network stream but need to store the current string if the value is a string or a number(majority of the time). Forward lets you not have to buffer the string internally or own more than a few iterators but precludes many data sources that are common to json. Random, similarly will allow for about the same as forward plus being able to use the json file as storage for many of the types or to do decoding on demand of the values(like numbers) but is the most restrictive on file types.
Is decoding to a variant/map like structure the most cost effective, it does allow for nice queries as some libraries have shown? It will definitely consume more memory than parsing direct to a previously known c++ structure with a little bit of boiler plate to join the json member names/types with the data structure.
Will there be more than one type? Like a parse to variant/map and a sax like version? But what restrictions on source types? Or with the variety of needs/methods would be best not to put the std stamp on one of the nine valid ways I listed.
Hi there,
I am wondering whether JSON [RFC7159] support would be a helpful extension to the C++ standard library
There are currently dozens of libraries [json.org] written in C or C++ solving these aspects. However, it would be of great convenience to have JSON be part of the C++ standard library. In particular, the wide use of JSON as exchange format for structured data as well as to express simple configuration data would could solve a lot of use cases within the C++ standard library.
On 3/2/17 7:51 AM, Daniel Frey wrote:
>> On 2 Mar 2017, at 10:16, olaf wrote:
>>
>> Op woensdag 1 maart 2017 22:25:33 UTC+1 schreef Niels Lohmann:
>> There are currently dozens of libraries [json.org] written in C or C++ solving these aspects. However, it would be of great convenience to have JSON be part of the C++ standard library. In particular, the wide use of JSON as exchange format for structured data as well as to express simple configuration data would could solve a lot of use cases within the C++ standard library.
>>
>> What's the advantage of a standard-library over a third-party library (in this case), apart from not being a dependency?
>
> As I wrote in more detail in another mail already, a standard SAX-like interfacewould allow different libraries or parts to be mixed by the user as
needed. With existing libraries it is often the choice between either/or.
>
That's not the question. The questions are -
a) what's the advantage of having something like this in the standard vs
the current situation where one imports code from some other place?
b) adding it to the standard would require adding features, reconciling
differing points of view, a ton of work to code the spec, and time taken
from other (more important/urgent) tasks. How would this benefit the
C++ community?
c) Why do we all have to agree on what a json library (or any non core)
library should look like? What's the point of that?
d) what value are we adding here - as opposed just the current situation?
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/3e0232a3-441d-d37d-9c99-75af009fb15c%40rrsd.com.
For some reason my mail client (MacOS Mail) screws up the quoting levels - sorry.
> On 2 Mar 2017, at 17:46, Nicol Bolas <jmck...@gmail.com> wrote:
>
> On Thursday, March 2, 2017 at 1:07:29 AM UTC-5, Daniel Frey wrote:
> > On 2 Mar 2017, at 06:52, Nicol Bolas <jmck...@gmail.com> wrote:
> >
> > Personally, I've always disliked the SAX approach, where reads are forced on you. I much prefer the reader approach, where you read at whatever pace you like. It's rather more like an iterator in that respect.
> >
> > Such an approach makes it very easy on the code doing the reading, since it can do things like pass the reader to other code to interpret those parameters. Doing this with a SAX interface requires basically writing a state machine into a type. And why would you want to encourage that kind of coding?
> >
> > You can get the same effects of a SAX interface with a Reader-like approach. Rather than standardizing the struct that interprets the JSON, you standardize the Reader as a Concept. A Reader has functions to read the next datum, tell you want that datum is, etc. And you can standardize a similar Writer Concept, which has interfaces for writing the data.
> >
> > So you get all of the benefits you outline, but without the huge detriment of using SAX to process stuff.
>
> I wonder if the SAX approach when combined with coroutines could provide the kind of decoupling you are looking for. We (the authors of taocpp/json and the PEGTL, which is the underlying parser library) are already waiting for coroutines to be able to play with pull-like interfaces instead of push-like interfaces. I do wonder about the efficiency, though. Anyways, for now, we are using the SAX-like interface and I'd like to see some real code of an alternative, as your above statement are too theoretical for me. Do you have a link to a library which uses such an approach?
>
> I haven't investigated JSON parsers, but Reader/StAX-style APIs are significant in the XML parsing world. C# lives by them; XMLReader and XMLWriter are the foundation of their XML processing systems. Even LibXML2 has a reader interface.
After reading the examples you linked, I still feel that JSON is different from XML.
And the SAX-like approach I am currently using is more light-weight
and can be used to feed a coroutine-based reader approach. I would like to explore this option with real code in the future, but for now I'll just keep it in the back of my head unless you could come up with something concrete :)
Also, you might have misunderstood the SAX approach wrt struct vs. concept. The struct I posted earlier implements the methods that the SAX interface (concept) requires.
> On 2 Mar 2017, at 20:41, Nicol Bolas <jmck...@gmail.com> wrote:
>
> I have a working understanding of SAX-style interfaces. My problem with SAX-style interfaces is that it forces you to implement a state machine, because all data is routed through a single object.
No.
> Pull APIs allow you to structure your code in a way that is structured. You get in a value. You test what it is. You then pass call a function to process that kind of data, passing it the StAX reader. That function reads more values, recursively descending through the JSON in a manner reminiscent of a recursive descent parser.
A pull interface like the one you linked as an example needs to track state of the current path, etc. and thus has a lot more overhead than the code I have right now.
> Push APIs require you to route all of this processing work through a single object. And therefore, it has to store which state its currently on, so that it can send that state the data in question. It's just a big pain to deal with, one which doesn't use the C++ stack effectively.
Wrong. Have you even looked at the examples I linked?
> On 2 Mar 2017, at 21:37, Nicol Bolas <jmck...@gmail.com> wrote:
>
> On Thursday, March 2, 2017 at 3:01:12 PM UTC-5, Daniel Frey wrote:
> > > On 2 Mar 2017, at 20:41, Nicol Bolas <jmck...@gmail.com> wrote:
> > >
> > > I have a working understanding of SAX-style interfaces. My problem with SAX-style interfaces is that it forces you to implement a state machine, because all data is routed through a single object.
>
> > No.
>
> Um... yes? Your examples show precisely that interface. Every time the parser reaches a new JSON value, you get a function call in that object. And therefore, it must forward that information to the place where it will actually be processed.
The "No" refers to "forces you to implement a state machine". You make a general claim that is simply not true. In some use-cases you might need a state machine, and in those use-cases the StAX approach might work better. But it's a trade-off, not a clear win. You are pessimizing other use-cases where the intermediate generic value (and a switch on the type) is not needed. An example would be a pretty printer.
Reading a file generates SAX events, passed directly to the SAX pretty printer. No json::value instance (or whatever the reader in the StAX case stores as its state) is created/updated.
> > > Pull APIs allow you to structure your code in a way that is structured. You get in a value. You test what it is. You then pass call a function to process that kind of data, passing it the StAX reader. That function reads more values, recursively descending through the JSON in a manner reminiscent of a recursive descent parser.
You are thinking of a use-case where you are not creating/using a generic JSON value, but a JSON value with a specific schema and you are skipping the JSON level, directly using the structure you are expecting, right? I can see how the StAX approach is helpful there, but...
> If you're referring to this post, those are examples of trivial things that don't need state, or whose state is trivial. "stringify" and "prettify" do the same operation on the same things, no matter where they appear in the JSON hierarhcy. Yes, SAX shines in such circumstances.
>
> But these are not useful circumstances for parsing JSON files. Generally speaking, the way you interpret data depends on how that data was interpreted before you.
...you are the one who defines for other what are "useful" circumstances?? You can't just declare everyone else's use-cases as "not useful" and only your own as "useful".
For me, your use-case never came up. In fact the most important use-case to me is:
* Construct json::value instances with an std::initializer_list directly in the code. (More information was in the presentation I linked earlier)
* Stringify the value.
* Efficiency - it must be *very* fast.
I don't think a StAX approach would benefit me.
Regarding external libraries - at the company where I work there was a veto on Boost libraries already before my time and the ban still stands (argument was that requiring to patch Boost before compiling it with xlC_r IBM compiler on AIX is not stable enough). In the end in my case it's easier to get a newer version of the compiler than to get a new library into a project (and IBM with poorly implemented C++11 support in their compiler on AIX surely doesn't help when arguing for the language). That's the state of things from where I stand.
I think that may be it. (I probably forgot something). That's core.
Having said that, the other question is:
Should the STL only do core?
Robert has some good reasons for 'yes'. I agree.
There are also good reasons for 'no':
1. other languages ship with more in the box
2. we have no good or (de facto) standard way to manage library packages.
3. Picking the right non-standard library takes time - just try starting a new Web project - with a new UI paradigm each week, there are too many choices - literally too many to be able to make an informed choice.
If we could do 2, that might lessen the need for 1.
Boost helps with 3. And 2 somewhat (and thus 1)
The biggest reason to limit the scope of the C++ libraries is that being
in an ISO standard makes it harder to change things later. Imagine what
Qt would look like now if it had needed to maintain compatibility with
the API it had 10+ years ago.
I want to work in the same way. I think you know about Boost.Property_tree. It's universal library for working with json, xml, ini and other formats. And i want see smth like this in the C++. What do you think about the idea?
Reason: Property_tree is universal represenation for data. And it's universal structure for creating parsers for JSON, XML, INI, etc. I am not sure, that si unviersal thing can work perfectly with each format (but why not?). And if we will add to Standard something really general with parsers for the most usable formats, it will be great!
Best regards,
Alexander Zaitsev
Hi there,
I am wondering whether JSON [RFC7159] support would be a helpful extension to the C++ standard library (pure library extension), including, but not limited to, the following aspects:
1. A variant-like container type (for this mail, let's call it "std::json") that combines C++ types for the JSON value types [RFC7159, chapter 3]:
- string (e.g. std::string),
- number (e.g., double or int64_t),
- boolean (e.g., bool),
- array (e.g., std::vector), and
- object (e.g., std::map).
This type should have an intuitive API (i.e., all expected container methods), but also use as much syntactic sugar as possible (e.g., using initializer lists to express arrays like "std::json my_array = {"a string", 17, 42.12};".
2. A serialization function to create a textual representation (called "JSON text" in [RFC7159]) from a std::json value that conforms to the JSON grammar [RFC7159, chapter 2-7].
3. A deserialization function (i.e., a parser) [RFC7159, chapter 9] to create a std::json value from a JSON text.
There are currently dozens of libraries [json.org] written in C or C++ solving these aspects. However, it would be of great convenience to have JSON be part of the C++ standard library. In particular, the wide use of JSON as exchange format for structured data as well as to express simple configuration data would could solve a lot of use cases within the C++ standard library.
I would be willing to draft a proposal based on the experience I made with my C++ JSON library [nlohmann/json]. Of course, I would be interested in your thoughts on this.
All the best,
Niels
References
[RFC7159] https://tools.ietf.org/html/rfc7159.html
[json.org] http://json.org
[nlohmann/json] https://github.com/nlohmann/json
Hello.I want to work in the same way. I think you know about Boost.Property_tree. It's universal library for working with json, xml, ini and other formats. And i want see smth like this in the C++. What do you think about the idea?
Reason: Property_tree is universal represenation for data. And it's universal structure for creating parsers for JSON, XML, INI, etc. I am not sure, that si unviersal thing can work perfectly with each format (but why not?). And if we will add to Standard something really general with parsers for the most usable formats, it will be great!
Hello.I want to work in the same way. I think you know about Boost.Property_tree. It's universal library for working with json, xml, ini and other formats.
Hi there,
I am wondering whether JSON [RFC7159] support would be a helpful extension to the C++ standard library (pure library extension), including, but not limited to, the following aspects:
1. A variant-like container type (for this mail, let's call it "std::json") that combines C++ types for the JSON value types [RFC7159, chapter 3]:
- string (e.g. std::string),
- number (e.g., double or int64_t),
- boolean (e.g., bool),
- array (e.g., std::vector), and
- object (e.g., std::map).
This type should have an intuitive API (i.e., all expected container methods), but also use as much syntactic sugar as possible (e.g., using initializer lists to express arrays like "std::json my_array = {"a string", 17, 42.12};".
2. A serialization function to create a textual representation (called "JSON text" in [RFC7159]) from a std::json value that conforms to the JSON grammar [RFC7159, chapter 2-7].
3. A deserialization function (i.e., a parser) [RFC7159, chapter 9] to create a std::json value from a JSON text.
There are currently dozens of libraries [json.org] written in C or C++ solving these aspects. However, it would be of great convenience to have JSON be part of the C++ standard library. In particular, the wide use of JSON as exchange format for structured data as well as to express simple configuration data would could solve a lot of use cases within the C++ standard library.
I would be willing to draft a proposal based on the experience I made with my C++ JSON library [nlohmann/json]. Of course, I would be interested in your thoughts on this.
All the best,
Niels
References
[RFC7159] https://tools.ietf.org/html/rfc7159.html
[json.org] http://json.org
[nlohmann/json] https://github.com/nlohmann/json
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/3DF8137F-C90E-4D25-96AB-FF8B766418DF%40nlohmann.me.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC2GhWVHd%3DrmQVenWZYihR7%2Bfz56NUmdNNx%3DiAr%3DQTcKFhuCzw%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/3DF8137F-C90E-4D25-96AB-FF8B766418DF%40nlohmann.me.
---Neal--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC2GhWVHd%3DrmQVenWZYihR7%2Bfz56NUmdNNx%3DiAr%3DQTcKFhuCzw%40mail.gmail.com.
I have been using this library for quite some time now, as part of a server application that communicates in JSON with client processes. It works beautifully.In terms of bringing it into the standard, I do have one reservation: due to the nature of the task at hand - mainly that the scope of "what do people want to use JSON for" is rather wide - it is under continuous improvement. It's averaging more than a commit per day over the last month. I can't see it as a project that will happily fit in with the much slower and more granular update process that it would be under if brought into the STL. I expect that many users will be using a more up to date version of the library from GitHub rather than stick to the version standardised e.g. 3 years prior.
I have been using this library for quite some time now, as part of a server application that communicates in JSON with client processes. It works beautifully.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/3DF8137F-C90E-4D25-96AB-FF8B766418DF%40nlohmann.me.
---Neal--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC2GhWVHd%3DrmQVenWZYihR7%2Bfz56NUmdNNx%3DiAr%3DQTcKFhuCzw%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC%2B0CCMfrW3aJCCL-gYo8RfiaT6ckOr3yG11maaUNjbS6DH3pg%40mail.gmail.com.
JSON itself is quite stable. Are the daily updates to this library actually meaningful to its interface? And if so, why is the interface undergoing daily revisions?
On Mon, Jun 25, 2018 at 4:38 PM, Jake Arkinstall <jake.ar...@gmail.com> wrote:I have been using this library for quite some time now, as part of a server application that communicates in JSON with client processes. It works beautifully.Have you compared it to competing json libraries such as rapidjson?
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC%2B0CCMSV9-oSood7iCU6d%3DBAJLHsfSBXUJAoCwpnRX69fj%3DuA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAEfefmwMH6s7t4aoGkpV9AnDZkDhWWgHhCF5W2qdrr8W2LoVQQ%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC%2B0CCMSV9-oSood7iCU6d%3DBAJLHsfSBXUJAoCwpnRX69fj%3DuA%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAEfefmwMH6s7t4aoGkpV9AnDZkDhWWgHhCF5W2qdrr8W2LoVQQ%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/6863e9aa-4a82-f032-677b-252f39c57f30%40gmail.com.
On Tuesday, 26 June 2018 07:25:38 PDT Richard Hodges wrote:
> A file parser's idiosyncrasies could be configured with a traits type.
That is not a good idea, as that would imply the parser for a complex file
format is entirely inline. No, if there's anything configurable, it ought to
be at runtime.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9595960.Ih0uOeaTLg%40tjmaciei-mobl1.
On 2018-06-26 05:54, Dejan Milosavljevic wrote:
> Why not also: XML, INI, csv, ASN.1, ... ?
XML might be a reasonable candidate, though it has even more problems
than JSON (e.g. DOM or SAX?).