I'm new to Python, been learning it at college and I have a question. First of all, this is the important part of the code in question:
#This is on my TCP client
name = raw_input("Box name: ")
timestamp = time.time()
json_dict = {'type': 'CREATE',
'name': name,
'timestamp': timestamp}
print json_dict
tcp_s.send(pickle.dumps(json_dict))
#This is on my TCP server
json_dict = pickle.loads(client_s.recv(65536))
file_received = json.dumps(json_dict,indent=4)
print file_received
Im basically trying to carry over information from the client to the server and have it convert into JSON, which is successful. My issue: the order in which it presents the type, name and timestamp tags arent as I want them to be. I think this might be due to using dictionaries which arent ordered and that is why Im here.
The current output:
{
"timestamp": 1492173052.087644,
"type": "CREATE",
"name": "test"
}
Any suggestion to have the output be like this?
{
"type": "CREATE",
"name": "test"
"timestamp": 1492173052.087644,
}