devops beginner

How to parse JSON configuration files in deployment scripts

Question

How do I read and parse JSON configuration files in a Perl deployment script?

Use the JSON module to decode configuration data:

#!/usr/bin/perl
use strict;
use warnings;
use JSON;
use File::Slurp;

my $config_file = 'deploy-config.json';
my $json_text = read_file($config_file);
my $config = decode_json($json_text);

print "Deploying to: $config->{environment}\n";
print "Server: $config->{server}{host}:$config->{server}{port}\n";

foreach my $service (@{$config->{services}}) {
    print "Starting service: $service->{name}\n";
    system("systemctl start $service->{name}");
}

This script reads a JSON config file, decodes it, and uses the data to control deployment actions.

Was this helpful?

Related Questions