I've got a serialized JSON structure that looks something like this:

{
    "title": "Webpage title",
    "major_categories": [
        {
            "title": "Major Category title",
            "categories": [
                {
                    "title": "Minor Category title",
                    "links": [
                        {
                            "url": "http://myurl.something.com";,
                            "label": "Text to display"
                        }
                    ]
                }
            ]
        }
    ]
}

Of course the arrays have more elements (the entire file is about 450 lines). My thought was to simply iterate through this structure using std.json and vibe.d/diet and basically build a webpage that way. My D get request handler is fairly simple:

void get() {
JSONValue json = parseJSON(new File("links.json", "r").readln('\x00'));
    string title = json["title"].str;
    JSONValue[] major_categories = json["major_categories"].array;
    render!("index.dt", title, major_categories);
}

My Diet is a little more complex, with three layers of foreach loops:

doctype html
html
    head
        title #{title}
    body
        h1 #{title}

        - foreach (major; major_categories)
            h2 #{major["title"].str}
            - foreach (minor; major["categories"].array)
                h4 #{minor["title"].str}
                p
                    - foreach (item; minor["links"].array)
a(href="#{item[\"url\"].str}") #{item["label"].str}
                        br

I realize all that is hard to read, sorry. :/

Anyway, my problem is that when I get about to line 320 of the JSON, the diet stops generating HTML. I've spit out the whole JSON run through the parser and back to string, and that has all the data, including the stuff that is cut out in the Diet. Basically I'm pretty sure it's not std.json (not 100% sure, since the operations I do in the diet are more complex, but essentially...). Does anyone have any insight to shine on this?

Reply via email to