Displaying better error message than “No JSON object could be decoded”

I’ve found that the simplejson module gives more descriptive errors in many cases where the built-in json module is vague. For instance, for the case of having a comma after the last item in a list: which is not very descriptive. The same operation with simplejson: Much better! Likewise for other common errors like capitalizing True.

Deserialize JSON with C#

You need to create a structure like this: Then you should be able to do: The names of my classes are just an example. You should use proper names. Adding a sample test: Produces:

How to send a Map in JSON

Key always should be string. Why it still doesn’t work? Because the error is caused by the redundant brace inside of “elementsToUpdate”. Below is an example:

jQuery AJAX cross domain

Use JSONP. jQuery: PHP: The echo might be wrong, it’s been a while since I’ve used php. In any case you need to output callbackName(‘jsonString’) notice the quotes. jQuery will pass it’s own callback name, so you need to get that from the GET params. And as Stefan Kendall posted, $.getJSON() is a shorthand method, but then you need to … Read more

How to overcome “datetime.datetime not JSON serializable”?

Updated for 2018 The original answer accommodated the way MongoDB “date” fields were represented as: {“$date”: 1506816000000} If you want a generic Python solution for serializing datetime to json, check out @jjmontes’ answer for a quick solution which requires no dependencies. As you are using mongoengine (per comments) and pymongo is a dependency, pymongo has built-in utilities to help … Read more

Return JSON response from Flask view

As of Flask 1.1.0 a view can directly return a Python dict and Flask will call jsonify automatically. If your Flask version is less than 1.1.0 or to return a different JSON-serializable object, import and use jsonify.