DeveloperBreeze

Read JSON Data from a File

# Import required module
import json

# Open and read JSON data from a file
with open('data.json', 'r') as file:
    data = json.load(file)

Continue Reading

Discover more amazing content handpicked just for you

Tutorial
javascript

التعامل مع JSON في JavaScript: قراءة البيانات وكتابتها

const jsonString = '{"name":"أحمد","age":30,"isMarried":false,"children":["سارة","علي"]}';

const person = JSON.parse(jsonString);
console.log(person.name);  // أحمد
console.log(person.age);   // 30

غالبًا ما يتم استخدام JSON في التفاعل مع واجهات برمجية (APIs) لجلب البيانات من الخادم. يمكنك استخدام fetch() في JavaScript لطلب بيانات JSON من API.

Sep 26, 2024
Read More
Tutorial
javascript

AJAX with JavaScript: A Practical Guide

In this guide, we've covered the basics of AJAX, focusing on how to make requests using both XMLHttpRequest and the modern Fetch API. AJAX allows you to create more dynamic and responsive web applications by enabling seamless communication between the client and server without reloading the entire page.

By mastering AJAX with JavaScript, you'll be able to implement interactive features like real-time updates, live data fetching, and much more in your web applications.

Sep 18, 2024
Read More
Tutorial
go

Building a RESTful API with Go and Gorilla Mux

func getBook(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")
	params := mux.Vars(r)
	for _, item := range books {
		if item.ID == params["id"] {
			json.NewEncoder(w).Encode(item)
			return
		}
	}
	json.NewEncoder(w).Encode(&Book{})
}

Add the createBook function to main.go:

Aug 12, 2024
Read More
Code
javascript json

How to Deep Clone a JavaScript Object

No preview available for this content.

Aug 12, 2024
Read More
Code
json python

Python Code Snippet: Simple RESTful API with FastAPI

from fastapi import FastAPI
from pydantic import BaseModel
from typing import List

app = FastAPI()

class Book(BaseModel):
    title: str
    author: str

# Sample data
books_db = [
    Book(title="The Catcher in the Rye", author="J.D. Salinger"),
    Book(title="To Kill a Mockingbird", author="Harper Lee"),
    Book(title="1984", author="George Orwell")
]

@app.get("/books/", response_model=List[Book])
async def get_books():
    return books_db

@app.post("/books/", response_model=Book)
async def add_book(book: Book):
    books_db.append(book)
    return book

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="127.0.0.1", port=8000)

Aug 04, 2024
Read More
Code
javascript json

JavaScript Code Snippet: Fetch and Display Data from an API

No preview available for this content.

Aug 04, 2024
Read More
Tutorial
python

Creating a Simple REST API with Flask

Create a file named app.py and add:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def home():
    return "Welcome to the Flask REST API!"

if __name__ == '__main__':
    app.run(debug=True)

Aug 03, 2024
Read More
Code
javascript

Fetch JSON Data from API in JavaScript

No preview available for this content.

Jan 26, 2024
Read More
Code
python

JSON Serialization and Deserialization

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Read and Write Files in Node.js using 'fs' module

No preview available for this content.

Jan 26, 2024
Read More
Code
php

JSON File Reading and Decoding

No preview available for this content.

Jan 26, 2024
Read More
Code
bash

Various cURL Examples for API Interactions

No preview available for this content.

Jan 26, 2024
Read More
Code
json python

Append Data to JSON File

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!