Skip to content
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

Realy? Object of type UUID is not JSON serializable #72

Open
TimurKady opened this issue Dec 29, 2021 · 2 comments
Open

Realy? Object of type UUID is not JSON serializable #72

TimurKady opened this issue Dec 29, 2021 · 2 comments

Comments

@TimurKady
Copy link

sheet = pe.get_sheet(model=model)
Error in formatting: TypeError: Object of type UUID is not JSON serializable.

@chfw
Copy link
Member

chfw commented Jan 20, 2022

True!

>>> import uuid
>>> b
UUID('d7aa5367-f4cd-4209-8591-38fc390584d5')
>>> import json
>>> json.dumps({'a': b})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
....
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type UUID is not JSON serializable

@StevenMapes
Copy link

If you want to use a UUID within JSON you have to convert it to a string

import json
from uuid import uuid4
b = uuid4()
print(json.dumps({'a': str(b)}))

Will print {"a": "2da1a2e6-6dbb-4a05-b2ef-cbe51519999b"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants