What Is JSON Format?

Join over 2 million students who advanced their careers with 365 Data Science. Learn from instructors who have worked at Meta, Spotify, Google, IKEA, Netflix, and Coca-Cola and master Python, SQL, Excel, machine learning, data analysis, AI fundamentals, and more.

Start for Free
Nikola Pulev 28 Apr 2023 5 min read


JSON Format

In this day and age, having data to analyze is arguably the most important weapon of businesses. Companies rage ferocious battles over the collection of more information for their data analysists and data scientists to draw conclusions from.

But it is not just the quantity that matters – targeting a very specific, quality and reliable source of data is crucial.

That’s why, more and more people are starting to use APIs, which, in turn, send this data in JSON format. 

Now, I know what some of you are thinking:

What exactly is an API?

Let me clarify. The abbreviation stands for Application Programming Interface. It basically defines how different software components should interact. In the context of data collection, you can think of APIs as a web server setup to return specific information when asked about it.

Some examples of API functions include a real-time weather forecast, up-to-date currency exchange rates etc.

As the purpose of these servers is to give specific data to another software, they don’t need to present it in a visual manner.

For simplicity, they respond with plain text.

And, in this article, we'll introduce you to the format of this text – JSON.

We’ll walk you through its definition, structure, usage, and syntax.

In addition, you’ll learn how it compares to the XML format. But let’s start from the beginning.

What is JSON?

JSON stands for ‘JavaScript Object Notation’, as it was derived from the JavaScript programming language.

It's a predictable, open-standard, language-independent format in which we exchange information with servers. Obviously, this makes using JSON beneficial for everyone involved. That's why the JSON format became widely popular. For instance, as we already mentioned, when we send a request to an API, data is often returned as a JSON. Another example is the payload data of a POST request which is also written in JSON.

The JSON format relies on 3 key concepts:

  • it should be easy for humans to read, write and understand;
  • easy for programs to process and generate, regardless of the programming language;
  • and, finally: written in plain text.

It achieves that by using conventions familiar to virtually all programmers, i.e. by building upon 2 common structures:

The first one is a collection of name/value pairs. In various languages, this data structure is familiar as a dictionary (Python), struct (C/C++), record (Pascal), object (JavaScript), associative array and so on.

The second structure in use is an ordered list of values. Most commonly this is realized as a list (Python), array (C/C++, Java, JavaScript and many more), vector or sequence.

These are universal data structures. Virtually all modern programming languages support them in one form or another. And, if you think about it, it only makes sense for a data format that is interchangeable with programming languages to also be based on these structures.

So, let’s take a look at how we write these in JSON.

What are the specifics of JSON syntax?

Here is a simple example of a dictionary object written in JSON: 

          “Country”: “Japan”,
          “Capital”: “Tokyo”,
          “Continent”: “Asia”

It starts with ‘{’ (left brace) and ends with ‘}’ (right brace). This particular example contains 3 keys – country, capital, and continent. Each key is followed by ‘:’ (colon) and its respective value. We separate the key/value pairs by ‘,’ (comma).

Regarding the array representation, here's how it looks: 


It starts with ‘[’ (left bracket), ends with ‘]’ (right bracket) and the items are separated by comma, similar to the dictionary.

You’ve probably noticed by now that the syntax for these structures is exactly the same when we write them in Python. This makes JSON extremely easy to handle and work with, especially in that programming language.

The examples we’ve just shown are extremely simplistic. In reality, The JSON format allows for mixing those two structures as the values themselves can be not only strings and numbers but other valid JSON representations. Thus, real-life JSON response may look more like this:

       “results”: [
                      “Country”: “Japan”,
                      “Capital”: “Tokyo”,
                      “Continent”: “Asia”
                      “Country”: “Austria”,
                      “Capital”: “Vienna”,
                      “Continent”: “Europe”
                      “Country”: “Canada”,
                      “Capital”: “Ottawa”,
                      “Continent”: “North America”
       “resultsCount”: 3

Here, we have a dictionary with 2 keys – “results” and “resultsCount”. The first one contains a list of dictionaries with data about a country. The second one stores how many items are in this list. In fact, this is a common practice when dealing with multiple results.

From this starting point, JSON files can potentially grow a lot in complexity with nested structures. Most APIs and other software returning JSON files should include documentation which clearly notes the layout and structure of the response. Therefore, complexity shouldn't present a problem.

JSON vs XML – What’s the difference?

Another commonly used standard for data transfer to and from servers is the XML format.

So, what are the main similarities and differences between JSON and XML?

Well, they both come in a human-readable form and can represent the same objects and information. However, JSON is less verbose than XML, as it uses fewer words in a simpler format to convey the same information. It is also far easier to translate into code. XML needs specialized, slow parsers that incorporate it into your program. And that is its main disadvantage.

That’s why JSON is slowly replacing XML in AJAX calls and other client-server interactions.

Some final words…

Now you’re familiar with the data transfer JSON format. You know what its purpose is and where we mainly use it. And, you understand the basics of its structure and syntax.

However, there are still tons of things to say about APIs, data extraction and web scraping in the context of data science.

So if you’re eager to learn more, check out our Web Scraping and API Fundamentals in Python course.

Ready to start learning data science?

Check out the complete Data Science Program today. Start with the fundamentals with our Statistics, Maths, and Excel courses, build up step-by-step experience with SQL, Python, R, and Tableau, and upgrade your skillset with Machine Learning, Deep Learning, Credit Risk Modeling, Time Series Analysis, and Customer Analytics in Python. If you still aren’t sure you want to turn your interest in data science into a solid career, we also offer a free preview version of the Data Science Program. You’ll receive 12 hours of beginner to advanced content for free. It’s a great way to see if the program is right for you.

Nikola Pulev

Instructor at 365 Data Science

Nikola Pulev is a University of Cambridge graduate, a data science practitioner, and instructor at 365 Data Science. An expert in Python modeling, Programming, and Mathematical Modeling, his courses have helped thousands of students master advanced topics of Web Scraping and API Fundamentals in Python and Convolutional Neural Networks with TensorFlow in Python.