This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Convert Flask’s request.get_json dict into a MultiDict like request.form

This was written to maintain a consistent API for interacting with both request.form and request.get_json(). This allows use to leverage .get with type coercion and .getlist.

Getting Started

Install the module with: pip install flask_json_multidict

# Load in our dependencies
from flask import Flask, request, jsonify
from flask_json_multidict import get_json_multidict

# Start an application
app = Flask(__name__)

def resolve_request_body():
    """Before every request, resolve `request.body` from either `request.form` or `request.get_json()`"""
    request.body = request.form
    if request.headers['content-type'] == 'application/json':
        request.body = get_json_multidict(request)

@app.route('/', methods=['POST'])
def root():
    """Reply with POST data as we see it"""
    body = request.body
    return jsonify({key: body[key] for key in body})
    # We can also leverage `request.body.getlist` as we do with `request.form`

if __name__ == '__main__':

# $ curl http://localhost:5000/ -X POST --data 'hello=world'
# {"hello": "world"}
# $ curl http://localhost:5000/ -X POST -H 'Content-Type: application/json' --data '{"hello": "world"}
# {"hello": "world"}


flask-json-multidict can be imported via flask_json_multidict.


get_json_multidict walks over the json provided by request.get_json() and returns a MultiDict.

  • request object - Current request being handled by Flask


  • body object - MultiDict with json information
    • If there were any dictionaries or nested lists, then these will be ignored as parameters
      • This is for consistency with how request.form behaves
# Assume we receive `{"colors": ["red", "blue"]}`
body = get_json_multidict(request)
body.getlist('colors')  # ['red', 'blue']

# Assume we receive `{"hello": "world"}`
body = get_json_multidict(request)
body.['hello']  # 'world'
body.get('hello')  # 'world'

# Assume we receive `{"foo": {"bar": "baz"}}`
# This is the silent ignore of bad parameters
body = get_json_multidict(request)
body.get('foo')  # None


In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Test via nosetests.


Copyright (c) 2015

Licensed under the MIT license.

Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
flask_json_multidict-1.0.0.tar.gz (11.0 kB) Copy SHA256 Checksum SHA256 Source Mar 4, 2015 (24.0 kB) Copy SHA256 Checksum SHA256 Source Mar 4, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting