从 JSON 文件中获取特定的 JSON 对象并将其写入另一个 JSON 文件

问题描述 投票:0回答:1

在邮递员项目中,我在单个环境 JSON 文件中维护多个变量。

为了维护代码,我想从 JSON 文件中获取特定的对象,这意味着所需的对象并写入新的 JSON 文件。(例如从附图中),想要获取键名称为“UTCDateTime”的对象并将其写入到一个单独的 JSON 文件中。

JS可以吗? 预先感谢

enter image description here

postman newman
1个回答
0
投票

此代码位于 python 3 中:


with open('[The file name you are reading]', 'r') as f:
    data = json.load(f)
    
    with open('[The file name you are writing to]', 'w') as r:
        loaded = json.dumps(f, r, indent=2)```
© www.soinside.com 2019 - 2024. All rights reserved.