首页 > 解决方案 > python & json - 如何将对象添加到对象

问题描述

{"something": {}}

如何在“某物”中添加另一个对象,例如

{"something": {"something2": "as"}}

我试过了append()update()但那些没有用。我还想添加尽可能多的数组和对象

标签: pythonjson

解决方案


该任务是使用 qed 进行的pip install jq

import json;
from jq import jq;

s='{"something": {}}';

data=json.loads(s);

answer=jq('.something = {"something2": "as"}').transform(data);

print(answer);

推荐阅读