You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无需Postman账号:如何将Postman备份文件转换为Collection文件

本地Postman备份转Collection V2(无需注册账号)

一、开源脚本转换(本地运行,无需注册)

可以用Python写一个简单的本地脚本,直接读取你的Postman本地备份JSON,提取并转换为标准Collection V2格式:

import json

# 读取本地Postman备份文件
with open('postman_backup.json', 'r', encoding='utf-8') as f:
    backup_data = json.load(f)

# 遍历所有本地Collection并转换
for idx, collection in enumerate(backup_data.get('collections', [])):
    # 构建V2格式的Collection结构
    v2_collection = {
        "info": {
            "_postman_id": collection.get('id', f"local-collection-{idx}"),
            "name": collection.get('name', f"Unnamed Collection {idx}"),
            "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
        },
        "item": []
    }

    # 处理请求和文件夹(转换为V2的item结构)
    def process_items(items, parent_item=None):
        target_list = v2_collection['item'] if not parent_item else parent_item['item']
        for item in items:
            if item.get('type') == 'request':
                # 转换请求结构
                request_item = {
                    "name": item.get('name'),
                    "request": {
                        "method": item.get('method'),
                        "url": item.get('url'),
                        "headers": item.get('headers', []),
                        "body": item.get('body', {})
                    },
                    "response": item.get('responses', [])
                }
                target_list.append(request_item)
            elif item.get('type') == 'folder':
                # 转换文件夹结构
                folder_item = {
                    "name": item.get('name'),
                    "item": []
                }
                target_list.append(folder_item)
                # 递归处理文件夹内的请求
                if item.get('requests'):
                    process_items(item['requests'], folder_item)

    # 开始处理当前Collection的内容
    if collection.get('requests'):
        process_items(collection['requests'])

    # 保存转换后的V2文件
    with open(f"{collection.get('name', f'collection_{idx}')}_v2.json", 'w', encoding='utf-8') as f:
        json.dump(v2_collection, f, indent=2, ensure_ascii=False)

使用方法:

  • 将你的Postman本地备份重命名为postman_backup.json,和脚本放在同一目录
  • 运行脚本,会生成每个Collection对应的V2格式JSON文件,可直接导入Insomnia、Thunder Client等工具

二、手动转换方法(无需工具)

如果不想用脚本,可以手动修改JSON结构:

  1. 打开你的Postman本地备份JSON,找到collections数组,每个元素就是一个本地Collection
  2. 新建一个空白JSON文件,按照以下V2模板填充:
{
  "info": {
    "_postman_id": "自定义ID(可随便填)",
    "name": "你的Collection名称",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "item": []
}
  1. 从备份的Collection中提取requests数组,将每个请求转换为V2格式的item:
    • 原请求的method、url、headers、body直接放到request字段下
    • 原请求的name作为item的name
    • 如果有文件夹,在item数组中添加{"name": "文件夹名", "item": []},然后把文件夹内的请求放到这个子数组里
  2. 保存修改后的JSON,即可导入其他工具

内容的提问来源于stack exchange,提问作者cmousset

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 19:40:19