common: Fix JSON string encoding for control characters

The implementation we got from json-glib is totally broken here
and escapes using octal sequences which are invalid in JSON.

Closes #582
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>