1

Another d3 question.

I am playing with the packed bubble example and I've got to a point where I'm trying to figure out how to load data without an external .json file. The sever this will be on eventually doesn't allow .json files and I'd rather not try to load the data with jsonp.

So I've tried to create a version that has the data stored as a variable in the code.

var jsonl = {"name": "","children": [{"name": "A","children": [{"name": "AA","children": [{"name": "AAB", "size": "10", "area": "10"}]},{"name": "AB","children": [{"name": "ABB", "size": "20", "area": "20"}]}]}]};

I am getting an uncaught syntax error unexpected token o error though. I've run the json through JSLint and it says it's good, so I'm not sure what the unexpected token is.

I've put the code on jsfiddle.

http://jsfiddle.net/9zpAN/

Any ideas?

lucastimmons
  • 151
  • 1
  • 3
  • 11

1 Answers1

5

You are trying to run JSON.parse on a JavaScript Object, while it expects a string: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON/parse

So, no need to parse; you already have the Object to work with.

nautat
  • 5,193
  • 32
  • 22