Boost logo

Boost Users :

Subject: Re: [Boost-users] [property_tree] Parsing JSON
From: Bryce Lelbach (admin_at_[hidden])
Date: 2011-01-02 12:52:46


-----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.

I've written most of the compiler (it's not lightning fast, but respectable for
now, and it can be optimized later). 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

// 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 :).

- --
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 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