python - python & json - 如何将对象添加到对象
问题描述
{"something": {}}
如何在“某物”中添加另一个对象,例如
{"something": {"something2": "as"}}
我试过了append()
,update()
但那些没有用。我还想添加尽可能多的数组和对象
解决方案
该任务是使用 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);
推荐阅读
- ios - 试图用文本保存 UIImage,它在 iPad 中看起来很模糊(swift)
- evaluation - 显式评级悖论
- json - 如何使用 azure 函数将包含 json 数据的 json 文件 url 或 url 文本文件读入字符串?
- azure - 无法将 Databricks 与 Azure Blob 存储连接
- c# - 获取用户在 Okta 中上次失败的登录
- javascript - Nodejs多个映射数组到单个Json文件
- python-3.x - jupyter - widgets.DatePicker 在 python pands 中转换为正确的数据格式
- swift - DispatchQueue 是否也锁定了里面使用的资源?
- flutter - 圈出数字
- bash - docker pull - Azure DevOps 中的无效参考格式