score:2

Accepted answer

the group lines in your json file should look like "group" : "2". also, your json contains a single object (resources); that's why your document.write is only called once. you'll need to iterate through the value of resources:

d3.json("test.json", function(error, graph) {
    var resources = graph.resources;
    for (var i = 0; i < resources.length; i++) {
        var obj = resources[i]
        for (var key in obj) {
            console.log(key+"="+obj[key]);
        }   
    }   
});

will get you

subject=node 1
group=1
...

score:0

i'd like to summarize what i've already wrote in several question's comments.

because posted json file was invalid it was not possible to iterate over it. original json file:

{
    "resources": 
    [
    {
        "subject": "node 1",
        "group" = "1"
    }, 
...
    {
        "object": "node 6",
        "group" = "6"
    }
    ]
}

each line which contains property group = "x" is wrong. it should be group : "x".

those kind of errors/typos are easily overlooked. they can be find out checking json file with proper tool like json validator. in this case jsonlint tool reported:

parse error on line 5:
...            "group"="1"        }    ]
----------------------^
expecting '}', ':', ',', ']'

after fixing format of file, iteration could be done easily using any loop: variable graph contains object resources, which is an array of objects. each of them contains common property group.


Related Query

More Query from same tag