VOOZH about

URL: https://thenewstack.io/an-introduction-to-json/

⇱ An Introduction to JSON - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2022-04-15 11:34:36
An Introduction to JSON
tutorial,
Cloud Services / Software Development

An Introduction to JSON

What JSON is and how it works.
Apr 15th, 2022 11:34am by Jack Wallen
👁 Featued image for: An Introduction to JSON

JSON stands for JavaScript Object Notation. It is a data interchange format, which is a fancy means of saying it’s a way of storing and transferring data. It has become widely deployed for quite a large number of use cases. And although the name implies JavaScript, JSON is used with other languages, such as Python, Ruby, PHP, and Java. More important, however, the JSON format is also used for Docker and Kubernetes manifests, so it’s absolutely crucial to understand how JSON works for anyone interested in cloud native development.

JSON came about as a subset of JavaScript in December of 1999 when object literals and array literals were added to JavaScript. JSON quickly became language-independent, such that almost every programming language was capable of parsing JSON data.

JSON wasn’t really invented by anyone in particular, as a number of different people realized how functional this data transfer/storage system would work. The term “JSON,” however, was coined by Atari employee Douglas Crockford. In 2002, Crockford went on to register the json.org domain. Crockford had become quite an important figure in technology (working at companies like Paypal), so his voice was instrumental in spreading the JSON word.

However, it wasn’t until the advent of the Single Page Application (SPA) that JSON usage really exploded, as both mobile and web applications required a seamless interchange of data. This is due to the succinct format of JSON data being considerably more efficient at sending data back and forth to a server, as compared to XML. One of the reasons for that is because JSON is a much more efficient and succinct language.

Here’s an example of XML:

<colors>
    <color>
        <colorname>Black</colorname> <hex>000000</hex>
    </color>
   <color>
        <colorname>White</colorname> <hex>FFFFFF</hex>
     </color>
     <color>
         <colorname>Red</colorname> <hex>FF0000</hex>
     </color>
</colors>

The JSON code for the above would be something like this:

{"colors": [
   {"colorname" : "Black", "hex" : "000000"},
   {"colorname" : "White", "hex" : "FFFFFF"},
   {"colorname" : "Red", "hex" : "FF0000"}
]}

As you can see, the JSON is not only much easier to write but easier to read.

JSON files use the .json extension but don’t be fooled into thinking you can only use JSON in .json files. In fact, all .yml and .yaml files are written in the JSON format, which (given how many applications and services depend on YAML files) is why it’s important to understand what JSON is and how it’s structured. If you want to deploy a container to a Kubernetes cluster, you’ll be using JSON. Want to build a Dockerfile, that’s right, you’re using JSON. There are even configuration files for desktop and server applications that depend on the JSON format.

Speaking of which…

JSON Structure

JSON files (be they .json, .yaml, or just about any file that depends on JSON) are built with two primary components:

  • A collection of name/value pairs.
  • An ordered list of values.

The structure of a JSON file is very much dependent on key-value pairs. Let’s say you want to build a JSON structured file that includes information about a user. That structure might look like this:

{
  "f_name" : "Jack",
  "l_name" : "Wallen",
  "gender" : "Male",
  "profession" : "Writer"
}

In the above example, we have four key-value pairs:

  • f_name – Jack
  • l_name – Wallen
  • gender – Mail
  • profession – Writer

Each pair is always set up in the form:

“key” : “value”

Both keys and values must be wrapped in double quotes. Keys always go to the left side of the colon and values on the right. Within each object, every key must be unique and can contain spaces. So, instead of “f_name”, you could use “first name”. However, I always avoid using spaces in keys, as it can get confusing.

Values are found on the right side of the colon and must be one of six data types:

  • Strings
  • Numbers
  • Objects
  • Arrays
  • Booleans
  • Null

You can also create a key-value pair using a nested object. Such a structure might look like this:

"user" : {
"f_name" : "Jack",
"l_name" : "Wallen",
"gender" : "Male",
"profession" : "Writer"
}

Above we have a key of “user” and a nested list of key-value pairs, consisting of “f_name”, “l_name”, “gender”, and “profession.

We can also use arrays within our key-value pairs. Arrays are housed with [ ]. Let’s continue with our example above, but we’ll add two more values to the “profession” key with an array. That would look like this:

"user" : {
"f_name" : "Jack",
"l_name" : "Wallen",
"gender" : "Male",
"profession" : [ "Writer", "Actor", "Technologist"]
}

Both of these examples bring up a very important point—indention. One of the caveats to using the JSON format is that indention absolutely must be consistent. As you can see above, my braces line up with one another as do my nested key-value pairs. If your indention isn’t consistent, whatever you’re using the JSON format for will not work. This is often a very challenging bit to debug, especially when your JSON-formatted manifests grow in length and complexity. Because of this, it’s always important that you indent with consistency from the very beginning.

JSON format can also be written out in a single line. Let’s take, for example, our “user” object. Instead of writing it out this way:

"user" : {
"f_name" : "Jack",
"l_name" : "Wallen",
"gender" : "Male",
"profession" : "Writer"
}

We can write it as a single-line string like so:

"user" : { "f_name" : "Jack", "l_name" : "Wallen", "gender" : "Male", "profession" : "Writer" }

Although you might think the above is easier to write out, in very long documents (especially when an array can become rather lengthy), the multi-line format is much easier to manage. This is especially so when crafting very complex container manifests.

Today, JSON is used everywhere: in SPAs, in local application configurations, in container manifests, in cloud native development, and APIs. You name it, and JSON is probably a part of it.

TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
TNS owner Insight Partners is an investor in: Docker, Writer.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.