GO-tv

Introduction

The current image has no alternative text. The file name is: IMG_20250829_023933_edit_182299874554995-scaled.jpg

JSON (JavaScript Object Notation) is a lightweight format for storing and exchanging data. It’s widely used in APIs, configuration files, and data storage. Python has a built-in json module that makes handling JSON simple and efficient.


1. Importing the JSON Module

import json

2. Converting Python Objects to JSON (Serialization)

import json

person = {
    "name": "Alice",
    "age": 25,
    "city": "Paris"
}

# Convert Python dict to JSON string
json_data = json.dumps(person)
print(json_data)

Output:

{"name": "Alice", "age": 25, "city": "Paris"}

3. Converting JSON to Python Objects (Deserialization)

json_str = '{"name": "Bob", "age": 30, "city": "London"}'

# Convert JSON string to Python dict
person_dict = json.loads(json_str)
print(person_dict["name"])   # Output: Bob

4. Working with JSON Files

Write JSON to File:

with open("data.json", "w") as f:
    json.dump(person, f)

Read JSON from File:

with open("data.json", "r") as f:
    data = json.load(f)
    print(data)

5. Pretty Printing JSON

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

Output:

{
    "name": "Alice",
    "age": 25,
    "city": "Paris"
}

6. Real-World Example: JSON from an API

import requests
import json

response = requests.get("https://api.github.com")
data = response.json()

print(data["current_user_url"])

Summary

  • Use the json module to serialize (dumps, dump) and deserialize (loads, load) JSON.
  • JSON is useful for APIs, configs, and data exchange.
  • Supports reading/writing JSON files.
  • Works seamlessly with third-party APIs.

⬇️ Download GO-tv تحميل Server 1 ⬇️ Download GO-tv تحميل Server 2 ⬇️ Download GO-tv تحميل Server 3

Related Posts

FlyFeditv

📘 Introduction In this project, you’ll create a command-line Expense Tracker that allows users to: ✅ Add expenses with category, amount, and description✅ View total spending and category breakdown✅ Automatically…

Read more

NetCinFly

📘 Introduction In this project, you’ll develop a Student Grades Analyzer in Python that can: This project helps you strengthen your skills with lists, dictionaries, loops, and data analysis logic….

Read more

Eagle_Pro

🌐 Introduction In this project, you’ll create a Web Scraper App in Python that extracts quotes, authors, and tags from a live website.You’ll use the BeautifulSoup and Requests libraries to…

Read more

Cobra_Pro

🌦️ Introduction In this project, you’ll build a Weather App in Python that retrieves live weather information from an online API.You’ll learn how to work with HTTP requests, JSON data,…

Read more

Show7-Pro

Concepts Covered: 🎯 Objective: Create a simple, text-based contact book application that allows users to: 💡 Code (contact_book.py): 🧠 Example Usage Console Output Example: 💾 Notes ⬇️ Download Show7-Pro تحميل…

Read more

Rapid_tv

🔹 Introduction The Rock, Paper, Scissors Game is a classic hand game that you can easily build in Python. 👉 Rules: 🔹 Code Example 🔹 Example Run 🔹 Concepts Learned…

Read more