JSON trong Python

Python cung cấp json.loads và json.dumps.

Điểm chính

Python cung cấp json.loads và json.dumps.

Phân tích JSON

import json
data = json.loads(text)

Chuyển thành chuỗi

text = json.dumps(data, indent=2)

Xác thực JSON

try:
    json.loads(text)
except json.JSONDecodeError as error:
    print(error)