el_pup_le
el_pup_le

Reputation: 12189

jsonschema python string encoded for error message

When using jsonschema to validate some json the error message prepends u to all the keys. Can this be avoided?

json = request.json_body

errors = jsonValidator.iter_errors(json)

Then error.message is

"{u'data': [{u'y': u'ho', u'x': u'2000-04-23'}, {u'y': 2, u'x': u'2000-04-24'}, {u'y': 4, u'x': u'2000-04-25'}], u'updated': u'2012-05-29T18:25:43.511Z', u'created': u'2012-04-23T18:25:43.511Z', u'user_id': u'1', u'title': u'Velocity vs Time upon blah blah'} is not of type 'array'"

Upvotes: 1

Views: 337

Answers (1)

FuzzyDuck
FuzzyDuck

Reputation: 1521

The u indicates that the key strings are encoded in Unicode. It's unlikely that this will cause any problems - u'data' is functionally equivalent to 'data' for your purposes, I would think.

Following on from your comment, you could use a simple string replacement operation to replace u' with ':

error.message.replace('u\'', '\'')

Upvotes: 1

Related Questions