Skip to content

Tag: json

TypeError: ObjectId(”) is not JSON serializable

My response back from MongoDB after querying an aggregated function on document using Python, It returns valid response and i can print it but can not return it. Error: Print: But When i try to return: It is RESTfull call: db is well connected and collection is there too and I got back valid expected result b…

‘dict’ object has no attribute ‘loads’

Im trying to create a simple key/value store client that accepts input from a text file like this This is the error I am getting I currently have the whole thing in a for loop to call the url for each new command but I’m having issues with any input file larger than 1 line. Here is my source, i’m

is not JSON serializable

I have the following ListView But I get following error: Any ideas ? Answer It’s worth noting that the QuerySet.values_list() method doesn’t actually return a list, but an object of type django.db.models.query.ValuesListQuerySet, in order to maintain Django’s goal of lazy evaluation, i.e. th…

dump json into yaml

I got a .json file (named it meta.json) like this: I would like to convert it to a .yaml file (named it meta.yaml) like : What I have done was : But sadly, what I got is following: Why? Answer pyyaml.dump() has an allow_unicode option that defaults to None (all non-ASCII characters in the output are escaped).…

Parsing JSON array into class instance objects?

I’m trying to parse some data in Python I have some JSON: If I wanted to parse the “metros” array into and array of Python class Metro objects, how would I setup the class? I was thinking: So I want to go through each metro and put the data into a corresponding Metro object and place that ob…

Return JSON response from Flask view

I have a function that analyzes a CSV file with Pandas and produces a dict with summary information. I want to return the results as a response from a Flask view. How do I return a JSON response? Answer A view can directly return a Python dict or list and Flask will call jsonify automatically. For older Flask…

Flask POST request is causing server to crash

I am trying to make a simple api in Flask, the first step being getting the POST json data. (I just want to print it for now) This is my code and when I request /api with json data, it returns a 500 error. Any thoughts on why this is happening? The curl command: body.json: Answer First what you want

How to JSON serialize sets?

I have a Python set that contains objects with __hash__ and __eq__ methods in order to make certain no duplicates are included in the collection. I need to json encode this result set, but passing even an empty set to the json.dumps method raises a TypeError. I know I can create an extension to the json.JSONE…

HTTP requests and JSON parsing in Python [duplicate]

This question already has answers here: How can I parse (read) and use JSON? (5 answers) What are the differences between the urllib, urllib2, urllib3 and requests module? (11 answers) Closed last month. I want to dynamically query Google Maps through the Google Directions API. As an example, this request cal…