Using JSON to configure your scripts
The target of this recipe is to show how to use JSON as a format for configuring a Groovy application.
The requirements for a configuration file format are:
Simple
Human-readable
Cross-platform
Multi-language support
Unicode support
JSON fully satisfies the above requirements, thus making a great candidate for configuring an application.
Getting ready
For this recipe, we work on a fictional application that maintains a connection to multiple databases. Each database has a number of parameters to configure such as host, port, credentials, and connection pool initial size.
The following is a sample JSON based configuration file for our application:
{
"configuration":{
"database":[
{
"name":"database1",
"host":"10.20.30.40",
"port":"4930",
"user":"user-alpha",
"password":"secret",
"pool-initial-size":"10",
"pool-max-size":"10"
},
{
"name":"database2",
"host":"192.168.10...