ujson option #1595

Closed
woozyking opened this Issue Sep 12, 2013 · 7 comments

Comments

Projects
None yet
3 participants
@woozyking

Hi,

Is it possible to use ujson as an optional JSON encoder/decoder for requests? Or, if ujson satisfies all the use cases of requests, replace simplejson with ujson?

@Lukasa

This comment has been minimized.

Show comment
Hide comment
@Lukasa

Lukasa Sep 12, 2013

Member

You absolutely can. The easiest way to do it is to monkeypatch:

import requests
import ujson

requests.models.json = ujson

That should cause all further calls to Response.json() to use ujson. As that's the only place in Requests that uses simplejson, that should cover everything.

Member

Lukasa commented Sep 12, 2013

You absolutely can. The easiest way to do it is to monkeypatch:

import requests
import ujson

requests.models.json = ujson

That should cause all further calls to Response.json() to use ujson. As that's the only place in Requests that uses simplejson, that should cover everything.

@woozyking

This comment has been minimized.

Show comment
Hide comment
@woozyking

woozyking Sep 12, 2013

So by looking at Response.json(), I reckon it's safe to use ujson as default for requests?

So by looking at Response.json(), I reckon it's safe to use ujson as default for requests?

@Lukasa

This comment has been minimized.

Show comment
Hide comment
@Lukasa

Lukasa Sep 12, 2013

Member

Certainly it will be safe to override that behaviour. For obvious reasons we won't change this in the core library, but I highly encourage you to use ujson if it suits your purpose better. =)

Member

Lukasa commented Sep 12, 2013

Certainly it will be safe to override that behaviour. For obvious reasons we won't change this in the core library, but I highly encourage you to use ujson if it suits your purpose better. =)

@woozyking

This comment has been minimized.

Show comment
Hide comment
@woozyking

woozyking Sep 12, 2013

Fair :)

Thank you @Lukasa !

Fair :)

Thank you @Lukasa !

@Lukasa

This comment has been minimized.

Show comment
Hide comment
@Lukasa

Lukasa Sep 12, 2013

Member

My pleasure, I hope you enjoy using Requests! =D Let us know if you have any problems. ⭐️

Member

Lukasa commented Sep 12, 2013

My pleasure, I hope you enjoy using Requests! =D Let us know if you have any problems. ⭐️

@Lukasa Lukasa closed this Sep 12, 2013

@ziadsawalha

This comment has been minimized.

Show comment
Hide comment
@ziadsawalha

ziadsawalha Dec 20, 2013

@Lukasa - would you consider using ujson by default if it is installed?

Something like:

# in compat.py
try:
    import ujson as json
except ImportError:
    try:
        import simplejson as json
    except ImportError:
        import json

@Lukasa - would you consider using ujson by default if it is installed?

Something like:

# in compat.py
try:
    import ujson as json
except ImportError:
    try:
        import simplejson as json
    except ImportError:
        import json
@Lukasa

This comment has been minimized.

Show comment
Hide comment
@Lukasa

Lukasa Dec 20, 2013

Member

Nope. =)

I see no reason for Requests to favour ujson over any other third-party JSON decoder. We do nothing very complicated with JSON decoding, so replacing the decoder we use either via monkeypatching or via doing the decoding yourself is totally safe. With that in mind, there's no good reason to move away from the standard library in Requests proper.

Member

Lukasa commented Dec 20, 2013

Nope. =)

I see no reason for Requests to favour ujson over any other third-party JSON decoder. We do nothing very complicated with JSON decoding, so replacing the decoder we use either via monkeypatching or via doing the decoding yourself is totally safe. With that in mind, there's no good reason to move away from the standard library in Requests proper.

@tarekziade tarekziade referenced this issue in mozilla-services/readinglist Mar 19, 2015

Closed

switch to ujson #199

@leplatrem leplatrem referenced this issue in mozilla-services/cliquet Mar 19, 2015

Merged

Use ujson #108

6 of 6 tasks complete

@joshowen joshowen referenced this issue in pynamodb/PynamoDB Sep 23, 2015

Closed

Use ujson if its available #78

@lockefox lockefox referenced this issue in EVEprosper/ProsperAPI Sep 28, 2017

Open

end-to-end ujson integration #17

0 of 4 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment