What is the best way to get access to nested JSON in D?

122 Views Asked by At

Now I am using vibed JSON module, but I do not know how to get access to nested elements without iteration it with foreach.

Here is my JSON:

{
    "hasMore": false,
    "result": [{
        "ip": "127.0.0.1",
        "passedtests": "[firsttest8,firsttest8,firsttest8,firsttest8]",
        "guid": ""
    }],
    "code": 201,
    "extra": {
        "stats": {
            "writesIgnored": 0,
            "scannedIndex": 0,
            "scannedFull": 1,
            "executionTime": 0,
            "filtered": 0,
            "writesExecuted": 0
        },
        "warnings": []
    },
    "error": false,
    "cached": false
}

I would like to do something like: result.passedtests. But here result is an array.

1

There are 1 best solutions below

1
On

I found perfect solution:

Json resultPassedtestsJson = visitorsInfo["result"][0]["passedtests"]; // "[firsttest8,firsttest8,firsttest8,firsttest8]"

[0] is because result is array, and we access to it's first element.