🛠️ToolsShed

JSON to Python

Convert JSON data to Python dict, dataclass, or TypedDict syntax.

Sıkça Sorulan Sorular

Kod Uygulaması

import json

json_str = '{"name": "Alice", "age": 30, "active": true}'
data = json.loads(json_str)
print(data)           # {'name': 'Alice', 'age': 30, 'active': True}
print(data["name"])   # Alice

# Using dataclass
from dataclasses import dataclass
from typing import Optional

@dataclass
class Person:
    name: str
    age: int
    active: bool

person = Person(**data)
print(person.name)    # Alice

# Using TypedDict
from typing import TypedDict

class PersonDict(TypedDict):
    name: str
    age: int
    active: bool

typed: PersonDict = data
print(typed["age"])   # 30

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.