Fix Python – Python: converting a list of dictionaries to json

I have a list of dictionaries, looking some thing like this:
list = [{‘id’: 123, ‘data’: ‘qwerty’, ‘indices’: [1,10]}, {‘id’: 345, ‘data’: ‘mnbvc’, ‘indices’: [2,11]}]

and so on. There may be more documents in the list. I need to convert these to one JSON document, that can be returned via bottle, and I cannot understand how to do this. Please he….

Fix Python – How to convert CSV file to multiline JSON?

Here’s my code, really simple stuff…
import csv
import json

csvfile = open(‘file.csv’, ‘r’)
jsonfile = open(‘file.json’, ‘w’)

fieldnames = (“FirstName”,”LastName”,”IDNumber”,”Message”)
reader = csv.DictReader( csvfile, fieldnames)
out = json.dumps( [ row for row in reader ] )

Declare some field names, the reader uses CSV t….

Fix Python – Format floats with standard json module

I am using the standard json module in python 2.6 to serialize a list of floats. However, I’m getting results like this:
>>> import json
>>> json.dumps([23.67, 23.97, 23.87])
‘[23.670000000000002, 23.969999999999999, 23.870000000000001]’

I want the floats to be formated with only two decimal digits. The output should look like this:
>>> json.dump….

Fix Python – Dump to JSON adds additional double quotes and escaping of quotes

I am retrieving Twitter data with a Python tool and dump these in JSON format to my disk. I noticed an unintended escaping of the entire data-string for a tweet being enclosed in double quotes. Furthermore, all double quotes of the actual JSON formatting are escaped with a backslash.
They look like this:

“{\”created_at\”:\”Fri Aug 08 11:04:40 +00….

Fix Python – Difference between data and json parameters in python requests package

What is the difference between the data and json parameters in the python Requests package?
It is unclear from the documentation
Does this code:
import requests
import json
d = {‘a’: 1}
response =, data=json.dumps(d))

Note that we convert the dict to JSON here ☝️ !
Do anything different than:
import requests
import json
d = {‘a’….

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

Python code to load data from some long complicated JSON file:
with open(filename, “r”) as f:
data = json.loads(

(note: the best code version should be:
with open(filename, “r”) as f:
data = json.load(f)

but both exhibit similar behavior)
For many types of JSON error (missing delimiters, incorrect backslashes in strings, etc), this ….

Fix Python – Loading and parsing a JSON file with multiple JSON objects

I am trying to load and parse a JSON file in Python. But I’m stuck trying to load the file:
import json
json_data = open(‘file’)
data = json.load(json_data)

ValueError: Extra data: line 2 column 1 – line 225116 column 1 (char 232 – 160128774)

I looked at 18.2. json — JSON encoder and decoder in the Python documentation, but it’s pretty d….

Fix Python – Python – Convert a bytes array into JSON format

I want to parse a bytes string in JSON format to convert it into python objects. This is the source I have:
my_bytes_value = b'[{\’Date\’: \’2016-05-21T21:35:40Z\’, \’CreationDate\’: \’2012-05-05\’, \’LogoType\’: \’png\’, \’Ref\’: 164611595, \’Classe\’: [\’Email addresses\’, \’Passwords\’],\’Link\’:\’\’}]’

And this is the desi….

Fix Python – Loading a file with more than one line of JSON into Pandas

I am trying to read in a JSON file into Python pandas (0.14.0) data frame. Here is the first line line of the JSON file:
{“votes”: {“funny”: 0, “useful”: 0, “cool”: 0}, “user_id”: “P_Mk0ygOilLJo4_WEvabAA”, “review_id”: “OeT5kgUOe3vcN7H6ImVmZQ”, “stars”: 3, “date”: “2005-08-26”, “text”: “This is a pretty typical cafe. The sandwiches and wraps are ….