Skip to content

Lesson 08 — Working with JSON

Almost every modern application exchanges data using JSON.

When you:

  • Launch an EC2 instance using AWS
  • Call an Azure API
  • Read Kubernetes configurations
  • Query ChatGPT
  • Retrieve GitHub repository information
  • Analyze security alerts
  • Work with cloud automation

…the data is usually transferred as JSON.

JSON is lightweight, human-readable, and easy for computers to process, making it the universal language for APIs and cloud services.

As a Cloud Engineer, DevOps Engineer, AI Engineer, or Cybersecurity Professional, you’ll work with JSON every day.


After completing this lesson, you will be able to:

  • Understand JSON.
  • Read JSON files.
  • Write JSON files.
  • Parse JSON data.
  • Convert Python objects to JSON.
  • Convert JSON into Python objects.
  • Work with nested JSON structures.
  • Apply JSON in Cloud Computing, DevOps, AI, and Cybersecurity.

JSON stands for:

JavaScript Object Notation

Although it originated from JavaScript, JSON is now supported by almost every programming language.

JSON is primarily used to exchange structured information between applications.


Modern technologies depend on JSON.

Examples include:

  • REST APIs
  • AWS Services
  • Azure Services
  • Google Cloud
  • Kubernetes
  • Docker
  • Terraform
  • AI APIs
  • Security Platforms

Without JSON, cloud automation would be significantly more difficult.


JSON is:

  • Lightweight
  • Human-readable
  • Easy to parse
  • Language-independent
  • Widely supported

These characteristics make JSON the preferred format for data exchange.


JSON stores information using Key : Value pairs.

Example:

{
"name": "GoHackersCloud",
"course": "Cloud Security",
"students": 10000
}

Every value is associated with a descriptive key.


JSON supports several data types.

JSON Type Example
String “AWS”
Number 100
Boolean true
Array [“EC2”,“S3”]
Object {“Region”:“Mumbai”}
Null null

These types closely match Python data structures.


A JSON object uses curly braces.

Example:

{
"Cloud":"AWS",
"Region":"Mumbai"
}

Objects contain multiple key-value pairs.


Arrays store multiple values.

Example:

{
"Regions": [
"Mumbai",
"London",
"Tokyo"
]
}

Arrays become Python lists after parsing.


Real-world APIs often return nested JSON.

Example:

{
"Instance": {
"ID":"i-123456",
"Status":"Running",
"Region":"ap-south-1"
}
}

Nested objects allow complex data to be represented in a structured way.


Python includes the built-in json module.

Import it:

import json

No additional installation is required.


Convert a dictionary into JSON.

import json
data = {
"Cloud":"AWS",
"Region":"Mumbai"
}
json_data = json.dumps(data)
print(json_data)

Output:

{"Cloud":"AWS","Region":"Mumbai"}

dumps() converts a Python object into a JSON string.


Convert JSON into a Python dictionary.

import json
text = '{"Cloud":"AWS"}'
data = json.loads(text)
print(data["Cloud"])

Output:

AWS

loads() converts JSON text into a Python object.


Example:

import json
with open("config.json") as file:
config = json.load(file)
print(config)

load() reads JSON directly from a file.


Example:

import json
settings = {
"Environment":"Production",
"Logging":True
}
with open("settings.json","w") as file:
json.dump(settings, file, indent=4)

The indent parameter formats the file for readability.


Example:

print(
json.dumps(
settings,
indent=4
)
)

Readable JSON is easier to debug and maintain.


Example:

print(config["Environment"])

Output:

Production

Nested values:

print(config["Database"]["Server"])

Example:

{
"Services":[
"EC2",
"S3",
"IAM"
]
}

Python:

for service in config["Services"]:
print(service)

Output:

EC2
S3
IAM

Example:

config["Region"] = "London"

Add a new value:

config["Backup"] = True

Python dictionaries make JSON data easy to modify.


Malformed JSON causes errors.

Incorrect:

{
Cloud:AWS
}

Correct:

{
"Cloud":"AWS"
}

Keys and string values must use double quotation marks.


Most APIs return JSON.

Example response:

{
"id":101,
"name":"Rahul",
"role":"Cloud Engineer"
}

Python:

import requests
response = requests.get(API_URL)
data = response.json()
print(data["name"])

The requests library automatically converts JSON responses into Python objects.


Cloud Engineers work with:

  • AWS CLI Output
  • CloudFormation Templates
  • IAM Policies
  • CloudTrail Events
  • API Responses

Example IAM policy:

{
"Version":"2012-10-17",
"Statement":[]
}

JSON is fundamental to cloud automation.


DevOps Engineers use JSON for:

  • CI/CD Configuration
  • Deployment Metadata
  • Monitoring Dashboards
  • Infrastructure Automation
  • Application Configuration

Many DevOps tools exchange information using JSON.


Security professionals analyze JSON from:

  • SIEM Platforms
  • EDR Solutions
  • Cloud Logs
  • Threat Intelligence Feeds
  • Security APIs

Example:

{
"EventID":4625,
"Status":"Failed Login"
}

Python scripts often parse this data for analysis.


AI applications exchange:

  • Model Responses
  • Prompts
  • Predictions
  • Embeddings
  • Configuration Files

Large Language Models commonly send and receive JSON data.


Beginners often:

  • Forget quotation marks.
  • Use single quotes instead of double quotes.
  • Access non-existent keys.
  • Modify immutable structures incorrectly.
  • Ignore malformed JSON.
  • Forget to validate API responses.

Careful validation improves reliability.


A Cloud Engineer retrieves AWS instance details.

import requests
response = requests.get(API_URL)
instance = response.json()
print(instance["InstanceId"])
print(instance["State"])

The script processes JSON returned by the cloud service and extracts useful information for automation.


As a Python developer:

  • Validate JSON before processing.
  • Use descriptive key names.
  • Keep JSON structures consistent.
  • Pretty-print configuration files.
  • Handle missing keys safely.
  • Avoid deeply nested objects where possible.
  • Store configuration separately from source code.
  • Validate API responses before using the data.

Good JSON practices improve maintainability and reduce runtime errors.


After completing this lesson, you should understand:

  • JSON fundamentals.
  • JSON objects.
  • JSON arrays.
  • Nested JSON.
  • Python json module.
  • load() and loads().
  • dump() and dumps().
  • Reading and writing JSON files.
  • Working with JSON APIs.

JSON is the standard data format for modern applications and cloud platforms.

By learning how to create, read, write, and manipulate JSON in Python, you’ve gained one of the most valuable skills required for Cloud Computing, DevOps, Artificial Intelligence, and Cybersecurity.

Nearly every API, cloud service, automation platform, and enterprise application relies on JSON for exchanging information.


➡️ Lesson 09 — Python Error Handling

In the next lesson, you’ll learn how to detect, handle, and recover from runtime errors using exceptions, try, except, else, and finally. These techniques will help you build reliable, production-ready Python applications that can gracefully handle unexpected situations.