I'm using d3.json to decode a dataset where the key/values are unknown. I need to convert the number values to numbers and leave the rest alone.
My JSON looks like this:
[{"file":"morning","row_total":"1095935","attr1":"79","attr2":""},
{"file":"noon","row_total":"221167","attr1":"174","attr2":"114"},
{"file":"night","row_total":"1317102","attr1":"253","attr2":"114"}]
It's read in from a PHP file with d3.json. For each value that can (without throwing NaN), I need to convert to a number (d3 uses the + symbol for this):
d3.json("getData.php", function(error, data) {
if (error) throw error;
data.forEach(function(d) {
if(!isNaN(d.i = +d.i)
d.i = +d.i
)})
Obviously there's an issue with my testing/looping logic. I would really appreciate some guidance here.
Thank you!