Slide 37
Slide 37 text
JsonSlurper for configuration files
import
groovy.json.*
import
static
groovy.json.JsonParserType.*
!
def
parser
=
new
JsonSlurper().setType(LAX)
!
def
conf
=
parser.parseText
'''
//
configuration
file
{
//
no
quote
for
key,
single
quoted
value
environment:
'production'
#
pound-‐style
comment
'server':
5
}
'''
!
assert
conf.environment
==
'production'
assert
conf.server
==
5
More tolerant parser:
single quotes,
non-quoted keys,
// and # comments,
missing comas