Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Chuyển JSON data thành Python tuple

Parse JSON thành dict (json.loads), rồi chuyển thành tuple bằng dict.items().

Ví dụ

import json
f = open('data.json')
data = json.load(f)
f.close()
print(tuple(data.items()))

Kết quả: tuple các cặp (key, value), value nested dict/list giữ nguyên.