Pretty printing is currently hard-coded. Custom generators let you customize the content of the JSON strings, pretty printing runs after the fact just adding line breaks and (currently hard-coded) indenting. It would be feasible to enhance by perhaps having an additional variant of prettyPrint with a map of options. For now you could cheat with regex:
import groovy.json.JsonOutput def ref = [name: 'Jason', properties: ['foo': 'bar']] def json = JsonOutput.toJson(ref) def shrinkSpaces = { _, leading, __ -> "${leading.replaceAll(' ',' ')}" } def findLeading = /(?m)^((\s{4})+)/ println JsonOutput.prettyPrint(json).replaceAll(findLeading, shrinkSpaces) Cheers, Paul. On Tue, May 19, 2020 at 7:06 PM Schalk Cronje <ysb...@gmail.com> wrote: > Is it possible to control the amount of spacing when pretty-printing > from JsonOutput? By default it uses 4, but I would like to use 2. I > could not see anything specific in JsonGenerator.Options either. > > -- > Schalk W. Cronjé > Twitter / Ello: @ysb33r > >