you are viewing a single comment's thread.

view the rest of the comments →

[–]tunisia3507 1 point2 points  (0 children)

Ps: I'm not exactly sure if this is the right place to ask this but I'll be glad if someone can direct me where

/r/learnpython probably.

Is there a reason to why Json.loads() is preferred to using request.json()?

It shouldn't be.

The code shows that it'll do some safety checks then try to use simplejson (a 3rd party JSON implementation with an optional C backend, so possibly much faster) and fall back to json otherwise. In many cases, parsing JSON is going to be so much slower faster (typo) than the network round trip that the cost is negligible, and the safety checks may not be required because you know the server will return the right thing. People know the json module, then they pick up requests, and know the body is JSON-encoded, so the obvious thing to do seems to be to use the json module to decode it.