What does data look like? (JSON)
In a previous blog post, I asked some questions about the general shape of data, and wondered if I could actually draw what it looked like.
That questioning led me to start investigating XML.
As a quick recap, XML is way of storing data, and it works by storing information in things called 'tags'.
By focusing on searching for a specific tag, you're able to locate specific information and do what you need to.
While XML is great, there's another data format that I'm personally more partial to: it's called JSON, and it's one of the most popular data formats out there (it's probably 'the' most popular one out there).
What is JSON?
The basic premise of JSON is similar to XML: it is a way to store and transmit information, and it's optimized to be human-readable and standardized.
They differ, however, in how they're shaped.
In each data point of a JSON file, instead of a pair of tags, there is something called a 'key-value pair'.
The 'key' part of the 'key-value' pair works kind of like a 'tag' in XML: it serves as a signal and gives people a general idea of the type of information they're looking at.
The actual information they're looking for is the 'value' part of the 'key-value' pair.
What does JSON look like?
I would describe a JSON entry as basically a bunch of these "key-value" pairs. Let's take a look at an example.
In the example above, we have the biodata of a certain person, stored in JSON format.
If someone wanted to make a JSON file of a person's biodata, they would start by pre-selecting a list of traits (first name, eye color, etc).
Each of those traits would then be assigned a 'key'.
Then, for each trait - or key - you would assign a 'value'. Pretty simple, right?
What is JSON used for?
The examples I've been sharing so far have been pretty simple. In reality, JSON could look a lot more complicated (and often does).
There are many reasons why someone might want to look under the hood of a JSON file. I use it in two main ways:
- I'm looking at hundreds (usually thousands) of entries formatted in a similar way, and I'm doing some calculations to figure something out about the group as a whole
- I'm looking at hundreds (usually thousands) of entries, and I'm running some kind of code to access a specific entry (or a list of entries that fit a certain criteria)
Anything else I need to know about JSON?
As this is only meant to be a small intro, there are a lot more rules for JSON that I didn't include here. I'd recommend reading other blogs to get a fuller understanding of what it is: