I'm currently trying to load in BLAST data (from a cool biological experiment) and showing it using Dynatable. I'm new to JSON and Javascript but I think I got the beginning up and running. The problem is that the JSON "object" has a nested instance in it and I'm not able to load that into Dynatable.
This is a snipped of the JSON
[{
"Hit_num": "1",
"Hit_id": "gi|495426285|ref|WP_008150982.1|",
"Hit_accession": "WP_008150982",
"Hit_hsps": {
"Hsp": {
"Hsp_num": "1",
"Hsp_bit-score": "202.986",
"Hsp_score": "515",
"Hsp_evalue": "1.7033e-61"
}
}
}, {
"Hit_num": "2",
"Hit_id": "gi|495936315|ref|WP_008660894.1|",
"Hit_accession": "WP_008660894",
"Hit_hsps": {
"Hsp": {
"Hsp_num": "1",
"Hsp_bit-score": "196.052",
"Hsp_score": "497",
"Hsp_evalue": "8.4357e-59"
}
}
}, {
"Hit_num": "3",
"Hit_id": "gi|495936314|ref|WP_008660893.1|",
"Hit_accession": "WP_008660893",
"Hit_hsps": {
"Hsp": {
"Hsp_num": "1",
"Hsp_bit-score": "185.652",
"Hsp_score": "470",
"Hsp_evalue": "6.08306e-55"
}
}
}]
As you can see it has a "Hit_hsps" and "Hsp" nesting in it. But every hit only has one Hit_hsps/HsP instance in it.
What would be the best way to go? Flatten the JSON file or is there a more ingenious way to deal with this kind of nested data in Dynatable?
I'm using this code to show the table
$(document).ready(function () {
$.dynatableSetup({
table: {
defaultColumnIdStyle: 'trimDash' //Make it accept _ spaced headers
}
});
$('#remote').dynatable({
dataset: {
records: JSON.parse($('#blast').text()) //Parse
}
});
});
The whole bunch is available on a JSFiddle