Traverse JSON trees

I believe that knowing how to traverse JSON trees is an important skill to master, particularly when designing applications that consume complex JSON structures through API requests.

When I recently started playing around the epynomous Wikipedia Viewer challenge on Free Code Camp, traversing the wikipedia API tree was an important first step. While there are many techniques, I decided to go for a recursive function approach. Pay attention however as Javascript creates a stack for each recursive call...

The way this works is straightforward:

  1. For each JSON object determine whether it is a defined (bang bang!!) object.
  2. If it is an object, recursively call the function to traverse it.
  3. If it is not an object (example: array, string, value), then it must be a leaf node!

Take the Wikipedia API JSON tree as an example which looks like this:

The traverse function will iterate through each object, but for the sake of this example, scanning through the first object of the Pages object will look like this:


Alexis said...

The team is innovative and knowledgeable best visual websites, going above and beyond to deliver results

Albert said...

Firstly boost earnings as well as Return on investment of marketing campaigns through traveling product sales through on-page structures optimization
branding advertising agency

Sarah Silva said...

The team is able to manage complex processes, and they care about their work. They often produce extra deliverables and new ideas because they know it will help the business.
mobile app consultant

Kelly Ramos said...

They were flexible and open to change, which made for a smooth development process
top branding

Sergio Lewis said...

Nobody can reject the info you have given in the blogs, this is actually a great work.
user interface design agencies

Charlie Freda said...

These are the great blogs; I assure you that I really enjoyed a lot in reading.
logo creator company

Kimberly Beckham said...

You create sense out of the foremost complex topics.
agency web design

Cheryl Terrell said...

Every day I visit a number of blog sites to see content, however this offers quality based content.
top UX companies

Margie Jones said...

Hmm!! This blog is really cool, I’m so lucky that I have reached here and got this awesome information.
top UX designers