improve json output in API, make yaml output not crash with bad unicode chars