DeveloperBreeze

JSON Serialization and Deserialization

import json

# Dictionary representing data
data = {'name': 'John', 'age': 30, 'city': 'New York'}

# Serialize (convert to JSON)
json_string = json.dumps(data)

# To parse JSON data (deserialize)
parsed_data = json.loads(json_string)

Continue Reading

Discover more amazing content handpicked just for you

Tutorial
javascript

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

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

const jsonString = JSON.stringify(person);
console.log(jsonString);

النتيجة:

Sep 26, 2024
Read More
Tutorial
javascript

AJAX with JavaScript: A Practical Guide

Here’s a basic overview:

Before the Fetch API, the traditional way to make AJAX requests was using XMLHttpRequest.

Sep 18, 2024
Read More
Tutorial
go

Building a RESTful API with Go and Gorilla Mux

Add the getBook function to main.go:

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{})
}

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

  • Get a specific item:
  curl http://127.0.0.1:5000/api/items/1

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

Read JSON Data from a File

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!