question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

allow custom JSONEncoder for the request's json param

See original GitHub issue

Using the json param when making a request is awesome:

payload = {'blip': 'blaz'}
r = requests.get('http://foo.bar', json=payload)

Using the response property is great as well, especially since you can use a custom json decoder:

r.json(cls=MyCustomDecoder)

It would be nice to allow a param to be passed that could be applied to the dumps of the json value.

payload = {'blip': Decimal(69)}
json_params = {'cls': MyCustomEncoder}
r = requests.get('http://foo.bar', json=payload, json_params=json_params)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
Lukasacommented, Sep 3, 2015

I think the better way is to manually use it yourself:

r = requests.post('http://foo.bar', data=json.dumps(some_data, cls=CustomJSONEncoder), headers={'Content-Type': 'application/json'})
4reactions
sigmavirus24commented, Sep 4, 2015

@drmaples then make a function that handles that “globally” for yourself. We won’t be introducing this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom JSONEncoder for requests.post - Stack Overflow
Is there any way to use custom JSON encoder with Request object? Seems I can only use parameter json, but can't find how...
Read more >
json — JSON encoder and decoder — Python 3.11.1 ...
To use a custom JSONEncoder subclass (e.g. one that overrides the default() method to serialize additional types), specify it with the cls kwarg;...
Read more >
Custom JSON Encoder in Python - PythonForBeginners.com
Create Custom JSON Encoder Using the “cls” Parameter​​ For converting a custom object to JSON, we need to define a custom JSONEncoder subclass ......
Read more >
Custom JSON encoder and decoder - Mathspp
This article explains how to extend the JSON format by using a custom encoder and a custom decoder to turn arbitrary Python objects...
Read more >
Encoding Custom Types to JSON - Real Python
In this video, you'll learn how to encode non-serializable types into JSON. The dump() and dumps() methods allow us to include an optional...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found