I am trying to iterate over and retrieve some data from JSON file using D3 Javascript.
Here is the JSON file:
{
"Resources":
[
{
"subject": "Node 1",
"group" : "1"
},
{
"predicate": "Node 2",
"group" : "2"
},
{
"object": "Node 3",
"group" : "3"
},
{
"subject": "Node 4",
"group" : "4"
},
{
"predicate": "Node 5",
"group" : "5"
},
{
"object": "Node 6",
"group" : "6"
}
]
}
This is my code in D3 Javascript for iterating and retrieving data:
d3.json("folder/sample.json", function(error, graph) {
document.write(graph.Resources[0].subject);
// The code for retrieving all the elements from the JSON file
});
The code above retrieves the first subject which is: Node 1
. I could not even retrieve the group
.
Could anyone please help me iterate over the JSON file Resources
and retrieve the elements: subject, predicate, object and group
, using any sort of iterations such as a for
loop.