【发布时间】:2020-08-28 00:14:09
【问题描述】:
我有一个 JSON 文件
[
{
"api_key": "123123112313121321",
"collaborators_count": 1,
"created_at": "",
"custom_event_fields_used": 0,
"discarded_app_versions": [],
"discarded_errors": [],
"errors_url": "https://api.bugsnag.com/projects/1231231231312/errors",
"events_url": "https://api.bugsnag.com/projects/1231231231213/events",
"global_grouping": [],
"html_url": "https://app.bugsnag.com/lol/kek/",
"id": "34234243224224",
"ignore_old_browsers": true,
"ignored_browser_versions": {},
"is_full_view": true,
"language": "javascript",
"location_grouping": [],
"name": "asdasdaasd",
"open_error_count": 3,
"release_stages": [
"production"
],
"resolve_on_deploy": false,
"slug": "wqeqweqwwqweq",
"type": "js",
"updated_at": "2020-04-06T15:22:10.480Z",
"url": "https://api.bugsnag.com/projects/12312312213123",
"url_whitelist": null
}
]
我需要删除除“id:”和“name:”之外的所有行并保留 JSON 结构。任何人都可以建议使用 Python 或 bash 脚本来处理这个问题吗?
【问题讨论】:
-
在加载 json 之后会像
dictionary所以只需删除你不需要的其他密钥dict.pop('key', None)或del dict["key"]
标签: python json python-3.x bash jq