Trim newlines from command outputs; cleans JSON representation.