json: convert value to string before encoding

If the JSON sent is not really a string, it's safer to try to convert it
to a string before calling the encode method. This way we can accept
integer as potentially valid strings.

Change-Id: Iad0b48f597a8c062cdb05c9bbb5342df15583edf