Any (working) JSON library for D2?

Adam D. Ruppe destructionator at gmail.com
Sun Jun 19 11:18:21 PDT 2011


Johannes Pfau wrote:
> I guess you do not have similar helper functions to parse JSON?

My other message has some. It isn't quite as nice to use though -
getting structs and such takes a little bit of work.

For example, I use it to get stuff from Facebook, and it
looks kinda like this:

===
	auto request = parseSignedRequest(signed_request).get!(Variant[string]);

	if("page" in request) {
		auto page = request["page"].get!(Variant[string]);
		pageId = page["id"].coerce!string;
		likes = page["liked"].get!bool;
	}
===

It's not as beautiful as it could be, but it works reasonably
well anyway, which is why I'm happy enough with it as it is.


> Also how do you workaround bug #2962?

I don't know anymore! For a while, I used a private fork of
std.json with the floating point functionality removed and
a utf related bug worked around, but now that fork is completely
commented out and I just use the stock std.json.

Problem is I don't remember if it's because the bugs got fixed
upstream, or if they just didn't bother me anymore...

Regardless though, it works in a test on my box at least.
Paste that code into a fresh file.


void main() {
	auto v = jsonToVariant("4.2");
	writeln(v.get!real);
}

compiles and runs correctly.


More information about the Digitalmars-d-learn mailing list