Replace all of the above with something like this:
```
class QueryForm(BaseForm):
    query = forms.CharField()
    indices = forms.CharField(required=False)
    def clean_query(self):
         try:
            return json.loads(self.cleaned_data['query'])
         except ValueError as x: 
            raise forms.ValidationError(x)
    def clean_indices(self):
         if self.cleaned_data['indices']:
             try:
                return json.loads(self.cleaned_data['indices'])
             except ValueError as x: 
                raise forms.ValidationError(x)

```
And then in the view do, the usual of...
```
form = QieruyForm(requeset.POST)
if not form.is_valid():
    return HttpResponseBadRequest(form.errors)
```
Also, that way you can send the JSON to the middleware without any pretty print indentation.