A bit of advice, please. I'm trying to parse a gzipped JSON file retrieved from the internet. The following naive implementation accomplishes the task:

auto url = "http://api.syosetu.com/novelapi/api/?out=json&lim=500&gzip=5";;
        getContent(url)
                .data
                .unzip
                .runEncoded!((input) {
                        ubyte[] content;
                        foreach (line; input.byLineRange!true) {
                                content ~= cast(ubyte[])line;
                        }
                        auto json = (cast(string)content).parseJSON;
                        foreach (size_t ndx, record; json) {
                                if (ndx == 0) continue;
                                auto title = json[ndx]["title"].str;
                                auto author = json[ndx]["writer"].str;
                                writefln("title: %s", title);
                                writefln("author: %s\n", author);
                        }
                });

However, I'm sure there is a much better way to accomplish this. Is there any way to accomplish something akin to:

auto url = "http://api.syosetu.com/novelapi/api/?out=json&lim=500&gzip=5";;
        getContent(url)
                .data
                .unzip
                .runEncoded!((input) {
                        foreach (record; input.data.parseJSON[1 .. $]) {
                                // use or update record as desired
                        }
                });

Thanks,
Andrew

Reply via email to