Skip to content

Instantly share code, notes, and snippets.

@dmcnulla
Created May 6, 2021 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmcnulla/50bb238e631c078b822a8be70096ccd2 to your computer and use it in GitHub Desktop.
Save dmcnulla/50bb238e631c078b822a8be70096ccd2 to your computer and use it in GitHub Desktop.
Converts postman output file to http format (http service in IntelliJ)
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