新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
python操作json_JSON/JSONB操作符
在Python中,我們通常使用json模塊來(lái)處理JSON數(shù)據(jù),以下是一些常用的操作:

讀取JSON文件
import json
with open('data.json', 'r') as f:
data = json.load(f)
寫入JSON文件
import json
data = {"name": "John", "age": 30, "city": "New York"}
with open('data.json', 'w') as f:
json.dump(data, f)
將JSON字符串轉(zhuǎn)換為Python對(duì)象
import json
json_string = '{"name": "John", "age": 30, "city": "New York"}'
data = json.loads(json_string)
將Python對(duì)象轉(zhuǎn)換為JSON字符串
import json
data = {"name": "John", "age": 30, "city": "New York"}
json_string = json.dumps(data)
對(duì)于PostgreSQL數(shù)據(jù)庫(kù)中的JSONB類型,我們可以使用以下操作:
插入JSONB數(shù)據(jù)
INSERT INTO table_name (jsonb_column) VALUES ('{"key": "value"}');
查詢JSONB數(shù)據(jù)
SELECT jsonb_column>'key' FROM table_name;
更新JSONB數(shù)據(jù)
UPDATE table_name SET jsonb_column = jsonb_column || '{"new_key": "new_value"}';
刪除JSONB數(shù)據(jù)
UPDATE table_name SET jsonb_column = jsonb_column 'key';
名稱欄目:python操作json_JSON/JSONB操作符
網(wǎng)頁(yè)鏈接:http://fisionsoft.com.cn/article/cdscgdp.html


咨詢
建站咨詢
