
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
json2html is a Python library that fetches data from APIs, allows users to define the structure of the JSON response, and generates responsive HTML pages to display the data in a user-friendly format.
json-2-html is a Python library that fetches data from APIs, allows users to define the structure of the JSON response, and generates responsive HTML pages to display the data in a user-friendly format.
This class is responsible for managing communication with the API and
retrieving JSON data.
It takes the API URL as input during initialization.
The fetch_data method sends a GET request to the API and returns the JSON
data.
It includes error handling for timeouts, connection errors, HTTP errors, and
invalid JSON responses.
This class is used to define the structure of the JSON data and how each
field should be displayed.
It uses an Enum called DisplayType to represent the different display types
(text, image, video, etc.).
The add_field method allows you to add a field definition, specifying the
field name, display type, and any additional options.
It includes validation to ensure that required options are provided for
certain display types (e.g., width and height for images).
This class generates the HTML code based on the JSON data and definitions
provided.
It uses the BeautifulSoup library to create and manipulate HTML elements.
The generate_html method iterates over the data and definitions, calling the
appropriate method to generate the HTML for each field.
It includes methods for adding the HTML head (with title and CSS links), and
for generating the HTML for different field types (text, image, video, file,
link).
It uses a templating engine (Jinja2) to separate the HTML code from the
Python code, making it easier to maintain and modify the HTML structure.
You can use this example code!
from json-into-html import ApiHandler, HtmlGenerator, JsonDefinition, DisplayType
# API address
api_url = "https://dog.ceo/api/breeds/image/random"
api_handler = ApiHandler(api_url)
data = api_handler.fetch_data()
if data:
json_definition = JsonDefinition()
json_definition.add_field("message", DisplayType.IMAGE)
json_definition.add_field("status", DisplayType.TEXT)
html_generator = HtmlGenerator(data, json_definition)
html = html_generator.generate_html()
html_generator.save_html("dog_image.html")
print("HTML generated successfully!")
else:
print("Failed to fetch data from API.")```
FAQs
json2html is a Python library that fetches data from APIs, allows users to define the structure of the JSON response, and generates responsive HTML pages to display the data in a user-friendly format.
We found that json-into-html demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.