Boost logo

Boost Users :

Subject: Re: [Boost-users] [property_tree] Parsing JSON
From: Olivier Tournaire (olitour_at_[hidden])
Date: 2011-01-02 14:05:32


Bryce,

2011/1/2 Bryce Lelbach <admin_at_[hidden]>

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Currently there's one piece missing from my JSON parser in prana, the
> compiler
> that turns the utree ast into the JSON object that the user would access.
>
> ATM the low level `parse_xxx(in, out)' interface for JSON is done, but this
> just produces a utree AST. The utree AST is useful for translating to other
> languages, or for applying generic utree algorithms to the JSON data, but
> it's
> not the ideal interface for less involved access. For that, we need a JSON
> specific data structure (as mentioned above) and compiler that can build
> said
> data structure from a utree AST.
>

OK. So, right now, nothing to acceess the parsed JSON structure. Am I right?

>
> I've written most of the compiler (it's not lightning fast, but respectable
> for
> now, and it can be optimized later).

For my particular application, fast running code is not really a
requirement.

> If you're seriously interested in using
> Prana's JSON parser, perhaps you could help me come up with the syntax and
> semantics for the interface that would be exposed? How would you like to
> access
> that member? A few ideas, (not mutually exclusive):
>
> std::ifstream ifs("foo.json", ifstream::in);
>
> prana::json_object js;
>
> prana::compile_json(ifs, js); // a number of types, such as a std::string,
> would
> // work for the first parameter.
>
> std::cout << js["results"]["artworkUrl100"] << std::endl; // no range check
> std::cout << js.at("results").at("artworkUrl100") << std::endl; // if out
> of range, throws
> std::cout << js.find_first("artworkUrl100") << std::endl; // null if not
> found
>

Yes, I like this kind of STL-like access. What about the property_tree
interface:

std::cout << js.get<value_type>("results.artworkUrl100") << std::endl;

?

And what about an access via index:

std::cout << js[1][4] << std::endl; // no range check
std::cout << js.at(1).at(4) << std::endl; // if out of range, throws

?

>
> // uri stuff isn't integrated yet, but in a few days you'd also be able to
> do:
>
> prana::uri_parts uri;
>
> prana::parse_uri(js["results"]["artworkUrl100"], uri);
>
> std::cout << uri.host << std::endl;
>
> I'm hoping to finish up the JSON and URI stuff in the next day or so. I'd
> love to
> hear some suggestions :).
>

OK. I will thus, impatiently, wait for the next few days. Would love to help
you, but as I really have no background with spirit, it is a little bit
hard.

Regards,

Olivier

> - --
> Bryce Lelbach aka wash
> boost-spirit.com
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAk0gu24ACgkQO/fqqIuE2t5S6QCgma4zlA/wp7sy7A6db/IF7VCC
> 0EkAn12l5qL57yESwcTGQSTu6FPpYzGS
> =ept9
> -----END PGP SIGNATURE-----
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://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