#!/usr/bin/env perl

use 5.010;
use strict;
use warnings;

use Text::CSV_XS;
use File::Slurper qw(write_text);
use JSON;

my $csv = Text::CSV_XS->new({binary => 1});
my $json = JSON->new->allow_nonref->pretty->canonical; # XXX: json doesn't support binary data!

for my $filename (glob("share/examples/*.csv")) {
    next if $filename =~ /TODO-|invalid-/;
    say "$filename ...";

    my $rows = [];
    open my($fh), "<:encoding(utf8)", $filename or die "Can't read '$filename': $!";
    while (my $row = $csv->getline($fh)) {
        push @$rows, $row;
    }

    write_text("$filename.json", $json->encode($rows));
}
