-
-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: 'URL' is not JSON serialisable #294
Comments
@darkfishy For what it's worth, this has nothing to do with Consider a similar example with a >>> import json
>>> import datetime
>>> now = datetime.datetime.now()
>>> json.dumps({"timestamp": now})
# ...
TypeError: Object of type datetime is not JSON serializable
>>> hasattr(now, "__str__")
True
>>> hasattr(now, "__repr__")
True The other difficulty in this case is that, though its common to serialize using the instance's Suggestion: use either >>> from yarl import URL
>>> u = URL("https://fm-data.herokuapp.com/api/marketplaces/436/currentHolding")
>>> import json
>>> json.dumps({"url": u}, default=lambda x: x.human_repr())
'{"url": "https://fm-data.herokuapp.com/api/marketplaces/436/currentHolding"}' |
@asvetlov this issue seems like it is not a bug and should probably be closed; it's common for custom object instances to not be serializable, and definitely applies in this case because |
Agree |
This happens when an object of type
yarl.URL
is in the value of any given key of any dictionary object.For instance:
Would this be an error with
yarl.URL
class orjson
library? It seems like either__str__()
or__repr__()
doesn't return a string?The text was updated successfully, but these errors were encountered: