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)

Related Posts

More content you might like

Tutorial
javascript

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

const fs = require('fs');

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

const jsonString = JSON.stringify(person, null, 2);

fs.writeFile('person.json', jsonString, (err) => {
    if (err) {
        console.error('حدث خطأ أثناء الكتابة إلى الملف', err);
    } else {
        console.log('تم كتابة الملف بنجاح!');
    }
});

قد يحتوي JSON على بيانات متداخلة مثل الكائنات داخل كائنات أو مصفوفات داخل كائنات. يمكنك التعامل مع هذه البيانات بنفس الطريقة التي تتعامل بها مع الكائنات والمصفوفات في JavaScript.

Sep 26, 2024
Read More
Tutorial
javascript

AJAX with JavaScript: A Practical Guide

While AJAX originally stood for "Asynchronous JavaScript and XML," JSON has become the most commonly used data format over XML.

When a user performs an action on the page, like clicking a button, JavaScript can send a request to a server, receive data, and update the page content without reloading the whole page.

Sep 18, 2024
Read More
Tutorial
go

Building a RESTful API with Go and Gorilla Mux

Add the createBook function to main.go:

func createBook(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")
	var book Book
	_ = json.NewDecoder(r.Body).Decode(&book)
	book.ID = "b" + string(len(books)+1) // Simple ID generation
	books = append(books, book)
	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

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!