Sanitize custom metadata to make sure we can encode it as JSON.