4 ms·
Why should I use either? I hope that’s not an obtuse question.
by mrfusion 5y ago
Why should I use either? I hope that’s not an obtuse question.
- simonw 5y agoI used Pydantic for a JSON API project recently and found it extremely useful. Say your API accepts the following JSON POST: POST /create-entry { "author_id": 123, "title": "My new blog post", "body": "<p>...</p>", "tags": ["writing", "productivity"] } Your API needs some validation here: some of these fields may be required. The "author_id" field must provide the ID of a valid author (that the API caller has permission to create posts for). The "tags" field must be an array. More importantly: if there is a validation error, you need to provide an error message explaining what was wrong. This can be quite tricky to do well, especially for complex nested JSON objects. Pydantic solves this problem really well - including returning detailed error messages helping show what went wrong.