Generating a Tree Diagram From External Data

Learn how to generate tree diagrams using external data.

In all the examples we have looked at so far, we have used data that we have declared from within the file itself. Being able to import data from an external file is an important feature that we need to know how to implement.

Data in a separate file

Starting from the simple tree diagram example that we began with at the start of the chapter, the first change that we need to make is to remove the section of code that declares our data. But don’t throw it away since we will use it to create a separate file called treeData.json. Its contents will be:

Get hands-on with 1200+ tech skills courses.