Python format issue with sending and receiving a file

87 views Asked by At

I am sending a JSON file from the cloud to a device using Azure IoT cloud-to-device messages via the Python SDKs.

The file contains lots of new lines and tabs which I would like to preserve. The file received of course must be in the exact same format as the one being sent.

This is on the sending end (cloud) :

FILENAME = "my_file.json"
f = open (FILENAME, "r")
data = f.read()
registry_manager.send_c2d_message(DEVICE_ID, data)

And on the receiving end (device) :

message = client.receive_message()
received_file = open("output.json", "w")
received_file.write(str(message))
received_file.close()

However the file contains just one line with the special characters b' \n \t , and not the actual tabs and new lines etc. Here is just the beginning of it :

b'{\n    "group1":\n    [\n        {\n    

How should I get this to format properly and not print the special characters, but instead lines and tabs etc.? Thanks in advance.

0

There are 0 answers