#!/usr/bin/perl
use strict;
use warnings;
use JSON;
use Data::Dumper;

# Specify the path to your JSON file
my $json_file = 'json.dr';


# Read JSON data from the file
open my $json_fh, '<', $json_file or die "Cannot open file: $!";
my $json_data = do { local $/; <$json_fh> };
close $json_fh;

# Parse JSON
my $data = decode_json($json_data);

# Generate HTML
my $html = generate_html($data);

# Print or do something with the HTML
print $html;




# Function to generate HTML from JSON list of objects
sub generate_html {
    my ($data) = @_;

    my $html = '<html><head><title>JSON List to HTML</title></head><body>';

    $html .= '<table border="1"><tr>';

    # Get the keys (column names) from the first object
    my @keys = sort keys %{ $data->[0] };

    # Create table header
    foreach my $key (@keys) {
        $html .= "<th>$key</th>";
    }

    $html .= '</tr>';

    # Create table rows
    foreach my $item (@$data) {
        $html .= '<tr>';
        foreach my $key (@keys) {
            my $value = $item->{$key};
            $html .= "<td>$value</td>";
        }
        $html .= '</tr>';
    }

    $html .= '</table>';
    $html .= '</body></html>';

    return $html;
}



