Adds compact output method.

Fixs #14470.
Merge pull request #14706 from alejansa/add_compact_output

Adds compact output method.