Created
May 6, 2021 00:16
-
-
Save dmcnulla/50bb238e631c078b822a8be70096ccd2 to your computer and use it in GitHub Desktop.
Converts postman output file to http format (http service in IntelliJ)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from os import listdir | |
BASE_PATH = '.' | |
if __name__ == '__main__': | |
for file in [f"{BASE_PATH}/{file_name}" for file_name in listdir(BASE_PATH) if file_name.endswith('.json')]: | |
with open(file) as json_file: | |
data = json.load(json_file) | |
items = data['item'] | |
if isinstance(items, list): | |
print(f"#{file}") | |
for item in data['item']: | |
print(f"\n\n### {item['name']}") | |
method = item['request']['method'] | |
print(f"{method} {item['request']['url']['raw'].replace('5080', '5000')}") | |
for header in item['request']['header']: | |
print(f"{header['key']}: {header['value']}") | |
print("\n") | |
if method in ['POST', 'PUT']: | |
try: | |
body = json.loads(item['request']['body']['raw']) | |
print(json.dumps(body, indent=2)) | |
except Exception as error_obj: | |
print(error_obj) | |
print('\n') | |
print('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment