Skip to content

Instantly share code, notes, and snippets.

@arifsuhan
Created March 11, 2023 18:20
Show Gist options
  • Save arifsuhan/754061a7ba0401da602f590bda2586f6 to your computer and use it in GitHub Desktop.
Save arifsuhan/754061a7ba0401da602f590bda2586f6 to your computer and use it in GitHub Desktop.
Postman Json Parsing to create mock csv
import json
def read_json(filename):
file = open(filename)
return json.load(file)
def dump_json(filename, data):
base_path = "mock_json"
filename = base_path + "/" + filename
# https://www.freecodecamp.org/news/python-json-how-to-convert-a-string-to-json/
json_object = json.loads(data)
json_object = json.dumps(json_object, indent=4)
with open(filename + ".json", "w") as outfile:
outfile.write(json_object)
def get_list(obj):
modules = data["item"]
for name in modules[:2]:
print("-----------------",name["name"], "-----------------")
go_deep(name)
def go_deep(obj):
if 'response' in obj:
try:
name = obj['name']
temp = obj["response"][0]
body = temp["body"]
mock_url = temp["originalRequest"]["url"]["raw"]
dump_json(name, body)
print(name)
# print(body)
print(mock_url)
except:
print("not found")
else:
for i in obj['item']:
go_deep(i)
filename = "mock_base.json"
data = read_json(filename)
get_list(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment