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

Does not support object hooks #358

Open
johann-petrak opened this issue Feb 28, 2020 · 7 comments
Open

Does not support object hooks #358

johann-petrak opened this issue Feb 28, 2020 · 7 comments
Labels
documentation Documentation help wanted Extra attention is needed

Comments

@johann-petrak
Copy link

The methods do not support the "object_hook" keyword argument. There also does not seem some other way to achieve the same result.

This seriously limits its usefulness. Are there any plans to implement object_hooks?

@vltr
Copy link

vltr commented Mar 12, 2020

@johann-petrak yup, ujson doesn't supports the object_hook keyword argument, but you can implement a __json__ callable in your object to be serialized, at you can see here. I know it's not as elegant as the object_hook method, but you can work around with that (at least). I hope this helps!

@johann-petrak
Copy link
Author

Thank you, I was not aware of that!
This is of limited usefulness because it seems to expect the complete JSON-String for an object which could be useful for strange flat fields in an object but kind of defies the purpose of ultrajson for complex nested objects.
However there is apparently also support for "toDict" which maybe could be used to recursively allow ultrajson to build the json for a dict-representation of any object.

It would maybe help more people to include this in the README?

@vltr
Copy link

vltr commented Mar 12, 2020

@johann-petrak I'm glad I could help! And I was not aware of the toDict method 😅

I think I made myself aware of __json__ when I read ujson source code, so, yes, either using the wiki or documenting ujson for these small hacks would be awesome (since knowing C is not a requirement to use ujson). I just bumped into your issue here and had an answer, I don't have any plans on contributing to this project (at least, not yet). I don't even know if there's any documentation done for the project or on the way. Bummer ...

@hugovk
Copy link
Member

hugovk commented Mar 12, 2020

Unfortunately the only documentation is the README, and PRs are very welcome to update that, or indeed write some "proper" docs :)

@vltr Thanks for your help commenting this and the other issue!

@vltr
Copy link

vltr commented Mar 12, 2020

@hugovk no problem, I'm glad I could help. Perhaps you want to tag this issue with "docs needed" and create a "docs" item on #352?

@hugovk hugovk added documentation Documentation help wanted Extra attention is needed labels Mar 12, 2020
@hugovk
Copy link
Member

hugovk commented Mar 12, 2020

✅ Labelled "documentation" and "help wanted". The #352 release has already been made :)

@vltr
Copy link

vltr commented Mar 12, 2020

"help wanted" is a life saver sometimes 😎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants