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.