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

Document option to use simplejson #1916

Closed
davidism opened this issue Jun 17, 2016 · 8 comments
Closed

Document option to use simplejson #1916

davidism opened this issue Jun 17, 2016 · 8 comments

Comments

@davidism
Copy link
Member

davidism commented Jun 17, 2016

Flask (through itsdangerous) prefers simplejson over the built-in json module if it is installed. The documentation should say that simplejson is an optional dependency and why using it is preferred but not required.

@davidism davidism added the docs label Jun 17, 2016
@davidism davidism added the json label Jun 26, 2016
@sentientcucumber
Copy link

sentientcucumber commented Jul 25, 2016

Sorry if this is a silly question; I'm new to the project (and Python) and want to make sure I understand clearly. I sifted through the issues and IRC history. simplejson is preferred because

  • It's faster
  • More up-to-date than the stdlib implementation.
  • json has various problems across different Python versions

Does that accurately summarize why simplejson is preferred?

@bladeoflight16
Copy link

bladeoflight16 commented Aug 10, 2016

I assume that since you intend to document it, you intend to support it? (So if itsdangerous decides to stop using simplejson, flask would continue to support it.) If so, why pull from itsdangerous? Why not just implement in flask itself and be done with it? itsdangerous' code for it is trivial:

try:
    import simplejson as json
except ImportError:
    import json

This is particularly important to me since simplejson supports Decimal and the built in json module does not (at least not in Python 2.7).

I know I'm getting a little off the topic for this issue, but have you considered just making it a dependency instead of making it optional? I had the rather strange experience of observing different behavior for Decimal just because I had simplejson installed in my virtualenv. My fellow developer did not, and so my code was broken on their machine and not mine.

@kblomqvist
Copy link
Contributor

What I'm missing here? I installed simplejson and assumed that it would be used instead of json. However, it seems not.

I would need simplejson to serialize Decimal when used in flask-sqlaclhemy model: db.Column(db.JSON()).

@davidism
Copy link
Member Author

That's not Flask, that's Flask-SQLAlchemy, a separate project.

@davidism
Copy link
Member Author

This is now mentioned in the installation docs as an optional dependency.

@dreamalligator
Copy link

dreamalligator commented Apr 12, 2019

wait, per what @kblomqvist was saying above, how do you "turn on" simplejson? does this just mean it is a recommendation to use it, or if you install it via pip/pipenv it will automatically be used?

found this issue after reading the documentation about optional dependencies and searching what that meant.

@MartinThoma
Copy link
Contributor

MartinThoma commented Oct 2, 2020

@sentientcucumber You wrote "[simplejson is] More up-to-date than the stdlib implementation.". What do you mean by that? Do you have a source for your claims that simplejson is faster / json has problems (in Python 3.4+)? Or is that maybe outdated?

I ran some benchmarks which indicated the speed of json and simplejson is about the same (and simplejson might rather be slower)

@pallets pallets locked and limited conversation to collaborators Oct 2, 2020
@davidism
Copy link
Member Author

davidism commented Oct 3, 2020

See #3555

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

No branches or pull requests

6 participants