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

add json serialization support for various types #27

Open
dsikes opened this issue Feb 27, 2023 · 3 comments · Fixed by #33
Open

add json serialization support for various types #27

dsikes opened this issue Feb 27, 2023 · 3 comments · Fixed by #33

Comments

@dsikes
Copy link
Contributor

dsikes commented Feb 27, 2023

Great work on this SDK.

This is a request for an enhancement to support JSON serialization for the different types supported

Eg:

import json
from pocketbase import PocketBase 

client = PocketBase('http://127.0.0.1:8090')

# authenticate as regular user
user_data = client.collection("users").auth_with_password("[email protected]", "thisIsAFaksePassword123")

# get a compliance report
report = client.collection("compliance").get_list()

print(json.dumps(report, indent=4))

This currently results in:

Traceback (most recent call last):
  File "/Users/dansikes/go/src/github.com/dsikes/equip/scripts/test.py", line 12, in <module>
    print(json.dumps(report, indent=4))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
          ^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/encoder.py", line 202, in encode
    chunks = list(chunks)
             ^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/encoder.py", line 439, in _iterencode
    o = _default(o)
        ^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type ListResult is not JSON serializable

Happy to work on a PR, but wanted to see if this was something you'd consider before doing so.

Thanks!

@vaphes
Copy link
Owner

vaphes commented Mar 1, 2023

@dslikes I think it would be really nice to have it! Please fell free to submit a PR and I will get it verified asap.

Thanks!

@ronnyandre
Copy link

Would absolutely love to have this feature!!

@vaphes vaphes closed this as completed in #33 Apr 9, 2023
@eevleevs
Copy link
Contributor

Please reopen, the solution was reverted by #42. This is still very much needed.

@vaphes vaphes reopened this Dec 16, 2024
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

Successfully merging a pull request may close this issue.

4 participants