Fix Python – Python – json without whitespaces

I just realized that json.dumps() adds spaces in the JSON object
e.g.
{‘duration’: ’02:55′, ‘name’: ‘flower’, ‘chg’: 0}

how can remove the spaces in order to make the JSON more compact and save bytes to be sent via HTTP?
such as:
{‘duration’:’02:55′,’name’:’flower’,’chg’:0}

….

Fix Python – JSON to pandas DataFrame

What I am trying to do is extract elevation data from a google maps API along a path specified by latitude and longitude coordinates as follows:
from urllib2 import Request, urlopen
import json

path1 = ‘42.974049,-81.205203|42.974298,-81.195755’
request=Request(‘http://maps.googleapis.com/maps/api/elevation/json?locations=’+path1+’&sensor=false’)….

Fix Python – Serializing class instance to JSON

I am trying to create a JSON string representation of a class instance and having difficulty. Let’s say the class is built like this:
class testclass:
value1 = “a”
value2 = “b”

A call to the json.dumps is made like this:
t = testclass()
json.dumps(t)

It is failing and telling me that the testclass is not JSON serializable.
TypeError: <__....

Fix Python – Python/Json:Expecting property name enclosed in double quotes

I’ve been trying to figure out a good way to load JSON objects in Python.
I send this json data:
{‘http://example.org/about’: {‘http://purl.org/dc/terms/title’: [{‘type’: ‘literal’, ‘value’: “Anna’s Homepage”}]}}

to the backend where it will be received as a string then I used json.loads(data) to parse it.
But each time I got the same exception :….

Fix Python – Converting JSON String to Dictionary Not List

I am trying to pass in a JSON file and convert the data into a dictionary.
So far, this is what I have done:
import json
json1_file = open(‘json1’)
json1_str = json1_file.read()
json1_data = json.loads(json1_str)

I’m expecting json1_data to be a dict type but it actually comes out as a list type when I check it with type(json1_data).
What am I m….

Fix Python – HTTP requests and JSON parsing in Python

I want to dynamically query Google Maps through the Google Directions API. As an example, this request calculates the route from Chicago, IL to Los Angeles, CA via two waypoints in Joplin, MO and Oklahoma City, OK:
http://maps.googleapis.com/maps/api/directions/json?origin=Chicago,IL&destination=Los+Angeles,CA&waypoints=Joplin,MO|Oklahoma+City,OK&….

Fix Python – What is the difference between json.load() and json.loads() functions

In Python, what is the difference between json.load() and json.loads()?
I guess that the load() function must be used with a file object (I need thus to use a context manager) while the loads() function take the path to the file as a string. It is a bit confusing.
Does the letter “s” in json.loads() stand for string?
Thanks a lot for your answers!….

Fix Python – Storing Python dictionaries

I’m used to bringing data in and out of Python using CSV files, but there are obvious challenges to this. Are there simple ways to store a dictionary (or sets of dictionaries) in a JSON or pickle file?
For example:
data = {}
data [‘key1’] = “keyinfo”
data [‘key2’] = “keyinfo2”

I would like to know both how to save this, and then how to load it ba….