This JSON represents a hierarchical structure with the CEO at the top, followed by various C-level executives, each managing their own departments and reporting teams.
Here is a Python CLI script to render a organizational chart into HTML. This script uses theargparselibrary to handle command-line arguments and thejsonlibrary to parse the JSON file. The HTML is generated using simple string formatting.
pythonCopy codeimport argparse
import json
import os
def generate_html(json_data):
def render_person(person):
html = f"{person['title']}: {person['name']}"
if 'reports' in person and person['reports']:
html += ""
for report in person['reports']:
html += render_person(report)
html += ""
html += ""
return html
def main():
parser = argparse.ArgumentParser(description='Render an org chart JSON file to HTML.')
parser.add_argument('input_file', type=str, help='Path to the input JSON file')
parser.add_argument('output_file', type=str, help='Path to the output HTML file')
code
args = <REDACTED>()
if not os.path.exists(args.input_file):
print(f"Error: The file {args.input_file} does not exist.")
return
with open(args.input_file, 'r') as f:
json_data = json.load(f)
html_content = generate_html(json_data)
with open(args.output_file, 'w') as f:
f.write(html_content)
print(f"HTML org chart has been written to {args.output_file}")
if name == 'main':
main()
Instructions for Running the Script
Save the above code to a file namedorg_chart_renderer.py.
Prepare your JSON file, for example,org_chart.json.
Open a terminal or command prompt and navigate to the directory containing theorg_chart_renderer.pyscript.
Run the script with the following command:shCopy codepython org_chart_renderer.py org_chart.json output.htmlReplaceorg_chart.jsonwith the path to your input JSON file andoutput.htmlwith the desired output HTML file name.
Save the above code to a file namedorg_chart_renderer.py.
Prepare your JSON file, for example,org_chart.json.
Open a terminal or command prompt and navigate to the directory containing theorg_chart_renderer.pyscript.
Replaceorg_chart.jsonwith the path to your input JSON file andoutput.htmlwith the desired output HTML file name.
This script will read the organizational chart from the specified JSON file and generate an HTML file representing the chart.
Cite this conversation
“Write me an orgchart for a fictional company in <REDACTED>.” Conversation with ChatGPT (version unspecified), from the ShareChat — Chatbot Conversations in the Wild dataset. The Chat Archive, 2026. https://thechatarchive.com/c/01m84w7aqxd16gns7212y84rkc