From a92fe7e2ef863d526abf3af335afd770e0a4c650 Mon Sep 17 00:00:00 2001 From: hmkamel Date: Sun, 12 May 2024 15:14:50 -0400 Subject: [PATCH] added reviewed MD file with Python script to convert JSON to MD --- import json_as_md.py | 60 ++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/import json_as_md.py b/import json_as_md.py index aea2056..9e5ca95 100644 --- a/import json_as_md.py +++ b/import json_as_md.py @@ -1,41 +1,57 @@ import json + # Function to extract endpoints from JSON data and write to markdown file def extract_and_write_endpoints(json_file_path, markdown_file_path): # Read JSON data from file - with open(json_file_path, 'r') as json_file: + with open(json_file_path, "r") as json_file: data = json.load(json_file) - + # Open markdown file for writing - with open(markdown_file_path, 'w') as markdown_file: + with open(markdown_file_path, "w") as markdown_file: # Iterate through JSON data and write endpoints to markdown file for category, endpoints in data.items(): - markdown_file.write(f'## {category}\n\n') + markdown_file.write(f"## {category}\n\n") for endpoint, details in endpoints.items(): - markdown_file.write(f'### {category}.{endpoint}()\n\n') - if 'note' in details: - markdown_file.write(''.join(details['note']) + '\n\n') + markdown_file.write(f"### {category}.{endpoint}()\n\n") + if "note" in details: + markdown_file.write("".join(details["note"]) + "\n\n") else: - markdown_file.write('No Description' + '\n\n') - + markdown_file.write("No Description" + "\n\n") + # Check if parameters exist - if 'parameters' in details: - markdown_file.write('| Parameter | Type | Description | Required |\n') - markdown_file.write('|:---------|:----:|:------------|:--------:|\n') - for param_name, param_details in details['parameters'].items(): - param_type = param_details.get('type', 'Unknown') # Check if 'type' key exists - param_note = param_details.get('note', 'No description available') # Check if 'note' key exists - required = param_details.get('required', False) # Check if 'required' key exists - markdown_file.write(f'| `{param_name}` | `{param_type}` | {param_note} | {"True" if required else "False"} |\n') - + if "parameters" in details: + markdown_file.write( + "| Parameter | Type | Description | Required |\n" + ) + markdown_file.write( + "|:---------|:----:|:------------|:--------:|\n" + ) + for param_name, param_details in details[ + "parameters" + ].items(): + param_type = param_details.get( + "type", "Unknown" + ) # Check if 'type' key exists + param_note = param_details.get( + "note", "No description available" + ) # Check if 'note' key exists + required = param_details.get( + "required", False + ) # Check if 'required' key exists + markdown_file.write( + f'| `{param_name}` | `{param_type}` | {param_note} | {"True" if required else "False"} |\n' + ) + markdown_file.write(f"\nlink: ```{details['link']}```\n\n") - + # Add the "---" line after all endpoints in the category are processed - markdown_file.write('---\n\n') + markdown_file.write("---\n\n") + # File paths -json_file_path = '/home/ham/Downloads/api.json' -markdown_file_path = 'methods.md' +json_file_path = "/home/ham/Downloads/api.json" +markdown_file_path = "methods.md" # Call the function extract_and_write_endpoints(json_file_path, markdown_file_path)