Make json look prettier in errors

Open
#243 13 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 6 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python

Research direction

The issue points to validation errors that use %r; start by locating that formatting path and reviewing how schemas and validated data are rendered. Decide how error messages should represent these values, then verify that the resulting output is valid JSON without Python representation artifacts such as u prefixes.

Written by the indexing model from the issue text.

Description

Dialects v2 Enhancement Error Reporting

I'm not sure if this is a real issue or not, but something that bothered me is that validation errors use "%r" as a format string which causes your json to look pretty ugly in the error message with all strings looking like {u'key':u'value'} instead of {"key":"value"}.

In my json API when I return an error it might be confusing for the developer using my API that there's suddenly and u in a string because that's not valid JSON.

Of course I could build a custom error message from all the errors I get, but that would be a bit tedious. Would it be something to consider to print the schemas and validated data as json strings instead of python dicts in error messages?

Perhaps it's something worth discussing.

Dominant language
Python
Stars
5k
Forks
741
Avg merge
4d 17h
Merged PRs (30d)
6

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python-jsonschema/jsonschema

All issues in python-jsonschema/jsonschema

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.