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?
- Use of PUT vs PATCH methods in REST API real life scenarios
- How do I POST JSON data with cURL?
- What is JSONP, and why was it created?
- How to parse data in JSON format?
- How to install JQ on Mac on the command line?
- How to read an external local JSON file in JavaScript?
- SyntaxError: Unexpected token o in JSON at position 1
- No module named MySQLdb
- Representing null in JSON
- Are multi-line strings allowed in JSON?
- Converting JSON data to Java object
- RecyclerView vs. ListView
- Django 2.1.3 Error: __init__() takes 1 positional argument but 2 were given
- OSError – Errno 13 Permission denied
- Pylint “unresolved import” error in Visual Studio Code
- How to create listview onItemclicklistener
- react router v^4.0.0 Uncaught TypeError: Cannot read property ‘location’ of undefined
- How to set environment variables in PyCharm?
- how to read json object in python
- JSON.parse unexpected token s
- How to filter JSON Data in JavaScript or jQuery?
- Fatal error: Maximum execution time of 30 seconds exceeded
- Returning JSON from a PHP Script
- How do I handle newlines in JSON?
- Error loading MySQLdb module: No module named ‘MySQLdb’
- android.content.res.Resources$NotFoundException: String resource ID #0x0
- “NS_ERROR_DOM_BAD_URI: Access to restricted URI denied”
- How to generate .json file with PHP?
- How to get POSTed JSON in Flask?
- Building a custom REST API
- What are the Oembed Links For?
- WP_Query result in form of Rest API results
- What is /wp-json?
- How to get the path to current theme, but from a JS file?
- WP Rest API v2 filter and display latest post with specific tag
- WP JSON list all permalinks
- Trying to get custom post meta through Jetpack JSON API [closed]
- WP Rest API v2 return posts with specific tag
- Importing JSON feed should the content be sanitized?
- how to get a more significant error response from ServerSideRender
- How to list categories and subcategories in JSON format?
- API JSON Data in WordPress
- fetch_feed: retrieve entries in the appearing order, not chronologically
- Generate dynamic page through data from another page
- Is there a get_post(s) filter that can alter/replace the output completely?
- WordPress REST API – Modify JSON before importing
- Most performant way of fetching remote API data?
- Dynamically insert values in a WordPress SelectControl Options field
- Run function when WordPress new multisite is created or ACF field is updated
- How to syntax Json output for translation?
- Intergrating agile carousel to wordpress: how to write the ajax_callback function
- How to enqueue or include json file to a plugin
- Ajax store response json in variables
- data (html) migration to posts
- body_class REST field in WP-API
- Using WP_Query to grab custom meta values, foreach to json object
- Why is json_decode failing?
- merge wp rest api query to get posts per category does not work
- Is there a way I can fetch the WordPress Developer Code References with an API?
- Strange “lea” prefix on wp-json
- URL rewrite with external JSON query
- Parse wordpress blog data using json api and ajax
- 403 error when publishing a post in wordpress. Error => Publishing failed. The response is not a valid JSON response
- Optimal WP Web App Backend for mobile app development
- WP REST API remove the WordPress shortcodes from the JSON wp/v2/posts content->rendered
- GET request return value as error instead of success
- ajax response strips multidimensional array and unable to decode
- How to save one API response to WooCommerce order meta data
- How can cookie/session authentication be used in wp-json fetch request?
- Memory Leak in Processing Large JSON file
- Get JSON from self hosted wordpress site
- Different way to export data from WP?
- Undefined property: stdClass::$ AND Trying to get property ‘name’ of non-object Error in plugin
- JSON webhook WP Automator – Help with Syntax [closed]
- Gutenberg core/file add style support in js/ json