I want to serialize my queryset, and I want it in a format as this view outputs:
class JSONListView(ListView): queryset = Users.objects.all() def get(self, request, *args, **kwargs): return HttpResponse(json.dumps({'data': [['bar','foo','bar','foo'],['foo','bar','foo','bar']]}, indent=4), content_type='application/json')
I simply don’t know how to output the queryset instead of the manual data in the example.
I’ve tried
json.dumps({"data": self.get_queryset()})
and
serializers.serialize("json", {'data': self.get_queryset()})
but it wont work. What am I doing wrong? Do I need to make a custom JSON Encoder?
Related Posts:
- How can I upgrade specific packages using pip and a requirements file?
- How to switch Python versions in Terminal?
- is not JSON serializable
- ‘NOT NULL constraint failed’ after adding to models.py
- django display message after POST form submit
- CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False
- “The path python3 (from –python=python3) does not exist” error
- How can I get the file name from request.FILES?
- Django TemplateDoesNotExist?
- Django: no such table: django_session
- Implementing a SOA in Django using celery
- NumPy array is not JSON serializable
- Django 1.7 upgrade error: AppRegistryNotReady: Apps aren’t loaded yet
- Python/Django: log to console under runserver, log to file under Apache
- What is a NoReverseMatch error, and how do I fix it?
- python: can’t open file ‘manage.py’: [Errno 2] No such file or directory
- What is the use of PYTHONUNBUFFERED in docker file?
- Cannot find command ‘git’ – windows
- How to revert the last migration?
- Getting stuck at Django error: No module named registration
- Django __str__ returned non-string (type NoneType)
- ow to ‘bulk update’ with Django?
- Why do I get sqlite error, “unable to open database file”?
- Why am I seeing “TypeError: string indices must be integers”?
- How to prettyprint a JSON file?
- ‘pip’ is not recognized as an internal or external command
- Can comments be used in JSON?
- pandas read_json: “If using all scalar values, you must pass an index”
- Can comments be used in JSON?
- Parse JSON in JavaScript? [duplicate]
- JSON parsing error syntax error unexpected end of input
- Angular: ‘Cannot find a differ supporting object ‘[object Object]’ of type ‘object’. NgFor only supports binding to Iterables such as Arrays’
- Why am I seeing “TypeError: string indices must be integers”?
- C# HttpClient An existing connection was forcibly closed by the remote host
- “SyntaxError: Unexpected token < in JSON at position 0"
- How to parse JSON in Java
- Grabbing the current viewer count for youtube live streaming
- “SyntaxError: Unexpected token < in JSON at position 0"
- How do I POST JSON data with cURL?
- How can I parse JSON with C#?
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- Use of PUT vs PATCH methods in REST API real life scenarios
- How do I POST JSON data with cURL?
- SyntaxError: Unexpected token o in JSON at position 1
- What is the easiest way to convert an Excel spreadsheet with tabular data to JSON? [closed]
- Converting dictionary to JSON
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- SyntaxError: Unexpected token o in JSON at position 1
- What is JSONP, and why was it created?
- TypeError: Converting circular structure to JSON in nodejs
- Can comments be used in JSON?
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- Where does pip install its packages?
- Does Python have a toString() equivalent, and can I convert a class to String?
- Use a JSON array with objects with javascript
- Yahoo Finance All Currencies quote API Documentation
- How to parse data in JSON format?
- What is BSON and exactly how is it different from JSON?
- Array of JSON Objects
- Chrome sendrequest error: TypeError: Converting circular structure to JSON
- Where does pip install its packages?
- How to convert JSON to XML or XML to JSON?
- django: TypeError: ‘tuple’ object is not callable
- How to reformat JSON in Notepad++?
- Fetch: POST JSON data
- json.dumps vs flask.jsonify
- Select objects based on value of variable in object using jq
- Uncaught SyntaxError: Unexpected token u in JSON at position 0
- Getting TypeError: __init__() missing 1 required positional argument: ‘on_delete’ when trying to add parent table after child table with entries
- Can’t fix “zipimport.ZipImportError: can’t decompress data; zlib not available” when I type in “python3.6 get-pip.py”
- No module named ‘psycopg2’
- Is #include
bad practice? - TypeError: unhashable type: ‘dict’, when dict used as a key for another dict
- uncaught syntaxerror unexpected token U JSON
- Getting TypeError: __init__() missing 1 required positional argument: ‘on_delete’ when trying to add parent table after child table with entries
- What is the difference between YAML and JSON?
- How to install JQ on Mac on the command line?
- Unexpected token u in JSON at position 0 (but only sometimes)
- No module named MySQLdb
- How to read an external local JSON file in JavaScript?
- Representing null in JSON
- What is the correct JSON content type?
- SyntaxError: Unexpected token o in JSON at position 1
- No module named MySQLdb
- SyntaxError: Unexpected token o in JSON at position 1
- How to check Django version
- pretty-print JSON using JavaScript
- pretty-print JSON using JavaScript
- What is deserialize and serialize in JSON?
- How to read an external local JSON file in JavaScript?
- C/C++ JSON parser
- python3 is not recognized as an internal or external command, operable program or batch file showing for creating django runserver
- Fastest JSON reader/writer for C++
- Representing null in JSON
- What is the convention in JSON for empty vs. null?
- YAML equivalent of array of objects in JSON
- What is the correct JSON content type?
- What is the correct JSON content type?
- Django: ImproperlyConfigured: The SECRET_KEY setting must not be empty
- Are multi-line strings allowed in JSON?