Data Responses from Web Servers (JSON vs XML)

Michael Causey
2 min readOct 17, 2020

In my post-Flatiron project builds, I decided to try my hand at a RSS Reader. I tend to get my news from multiple sources, depending on topic. Sports news may come from ESPN or Bleacher Report, tech news from TechCrunch, etc. As I was coming up with ideas to make my life easier with my new skillset, I landed on an idea of all my sources in one place. As I started to research how this would work, it lead me to RSS feeds, the return of the data in XML (Extensible Markup Language) format, and the differences from the JSON (JavaScript Object Notation) information I had previously worked with in previous projects. This post will help distinguish between the two data types.

Similiarities

Let’s start with how they are similar. A simple eye-test can show that they are alike in some ways. Both are hierarchal in structure, having values with a parent-child relationship, and both can be parsed through in order to pull data from within each feed. The first difference I noticed was in how to parse the data wanted for the purposes of my RSS Reader.

Differences

The first one I noticed is that unlike JSON, XML does not use arrays, so using array functions like .map does not work. To get around this, I used methods like .querySelector in order to pull the information I was looking for. Secondly, how it is parsed once it is retrieved from its source. When data is pulled from a RSS feed, and XML DOM has to be created and the data has to be parsed into it before it can be used. Below is my example of a XML parse from an RSS source.

Example of XML fetch

For comparison, here is a similar pull from an external API I had built in a different project.

Example of JSON fetch

The last thing I noticed was that JSON tends to be faster in relaying its responses. XML tends to me larger files in general, so that may be a piece of it, but I’m continuing to explore the differences and uses of each.

--

--

Michael Causey

Flatiron School DC. Learning to code one day at a time.