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

The choice for lack of dict key encoding should be documented #103

Closed
pjrobertson opened this issue Aug 17, 2014 · 3 comments
Closed

The choice for lack of dict key encoding should be documented #103

pjrobertson opened this issue Aug 17, 2014 · 3 comments

Comments

@pjrobertson
Copy link

#100 gives a really good outline as to why you can't do something like:

json.dumps({<MyObject: Cool Thing> : 'string'}, cls=EvenWithACustomEncoder)

I think this fact (And the arguments against it) should be in the docs.

I'm sorry I can't provide any suggested wording or other ideas at this time. At the least, a sentence like this would suffice:

"There is no way to encode custom objects when they are used as dict keys, the reasons are explained here: <link to issue #100>"

JBaldachino added a commit to JBaldachino/simplejson that referenced this issue Aug 18, 2014
Document limitations to key encoding ref simplejson#103
JBaldachino added a commit to JBaldachino/simplejson that referenced this issue Aug 18, 2014
@JBaldachino
Copy link

For what it's worth, I did find that despite the excellent advice there, simplejson could not meet my needs. Perhaps there was something lacking in my implementation, but I had trouble while testing different fringe cases. Worried that my work-arounds were becoming too convoluted, I switched this leg of our stack to serialize/deserialize using PyYAML, a more complicated but robust solution.

I agree that it would be good to at least document the limitation to save others time, and as such I proposed a small addition to the docs. Feel free to edit for style or expand, just wanted to help get the ball rolling.

@etrepum
Copy link
Member

etrepum commented Aug 18, 2014

YAML is much more appropriate if you're looking to serialize arbitrary stuff in arbitrary ways. simplejson is limited by the very rigid JSON format, YAML is far more extensible (which is why there have been so many problems with it, especially with regard to security).

@etrepum
Copy link
Member

etrepum commented Aug 18, 2014

If you're willing to layer additional semantics on top of JSON there are projects such as JSON-RPC or Transit. Note that these are still typically implemented with simplejson under the hood, but vend a higher level API.

@etrepum etrepum closed this as completed Aug 18, 2014
jsonn pushed a commit to jsonn/pkgsrc that referenced this issue Aug 26, 2014
Version 3.6.3 released 2014-08-18

* Documentation updates
  simplejson/simplejson#103
jsonn pushed a commit to jsonn/pkgsrc that referenced this issue Oct 11, 2014
Version 3.6.3 released 2014-08-18

* Documentation updates
  simplejson/simplejson#103
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