Fix encoding issues in nested output

This fixes #15542
Remove unused import
Merge pull request #15854 from terminalmage/bp-15546

Backport #15546 to 2014.7 branch