Question: How would I make Python return something like this:

```
{ "status": error,
  "location": loc,
  "codes": {
      "code1": 5,
      "code2": 6,
  },
}

```

I think this looks like a JSON object?

Answer: 
If that is indeed a JSON object, you would want to use the JSON encoder/decoder that is part of the Python Standard Library. See [the official Python documentation](https://docs.python.org/3.5/library/json.html) for more information on it. It has a well-written basic usage section, and good examples.

That library, once imported, should allow you to have functions return JSON objects by using functions like `json.encode` and `json.default`.
What you have in your question looks like a Python dictionary. Since you want to know how one can return something like that, your question has two parts:

* the first part deals with [function usages](http://www.tutorialspoint.com/python/python_functions.htm)
* the second part deals with building up the [dictionary itself](http://learnpythonthehardway.org/book/ex39.html)

Luckily, these simple problems are well-documented and one can find the answer with smaller effort than by asking a question.