When it comes to the structure of a JSON file, there is no one-size-fits-all correct format. It all depends on the specific code you are working with.
If you're wondering how to convert a CSV file into a JSON file based on a particular code snippet, like the one you provided, you need to look at how the d3.csv
function creates an array of objects. In the example code you linked, each object in the array has an "id" and a "value" key/value pair.
So, your JSON file should have a similar structure:
[{
"id": "flare.analytics.cluster.AgglomerativeCluster",
"value": 1938
}, {
"id": "flare.analytics.cluster.CommunityStructure",
"value": 3812
}, {
"id": "flare.analytics.cluster.HierarchicalCluster",
"value": 2714
}, {
"id": "flare.analytics.cluster.MergeEdge",
"value": 1743
}]
If you're creating your own JSON file, you don't necessarily need to follow the row function that removes objects without a "value" property and converts values to numbers.
You can check out an updated version of the bl.ocks using a JSON file here: https://bl.ocks.org/anonymous/4ca57ea4393a37bc92091325eba295dd
Just keep in mind that if you use a different data structure like the one described in your question...
[{"Name": "mathematics", "completed-tests": 340}, etc...]
...you will need to modify Bostock's code accordingly, particularly in the d3.hierarchy
and node
selection sections.