I'm stuck trying to read the files in google colab, It should read the file as a simple JSON but I can't even do a json.dumps(file) without getting 100 of errors
Uploading the file:
import json
import csv
from google.colab import files
uploaded = files.upload()
Printing works, It shows the content of the file:
print(uploaded)
data = json.dumps(uploaded)
But I get Object of type 'bytes' is not JSON serializable when trying to do json.dumps(uploaded)
Shouldn't the file be read as json and not bytes? In some other cases, I tested it also read as dictionary
JSON file:
[
{
"type": "message",
"subtype": "channel_join",
"ts": "123",
"user": "DWADAWD",
"text": "<@DWADAWD> has joined the channel"
},
{
"type": "message",
"subtype": "channel_join",
"ts": "123",
"user": "DWADAWD",
"text": "<@DWADAWD> has joined the channel"
},
{
"text": "Let's chat",
"user_profile": {
"display_name": "XASD",
"team": "TDF31231",
"name": "XASD",
"is_restricted": false,
"is_ultra_restricted": false
},
"blocks": [
{
"type": "rich_text",
"block_id": "2N1",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "Let's chat"
}
]
}
]
}
]
}
]
If you upload just 1 file. You can get the content from its values()
data = next(iter(uploaded.values()))
Then, you can convert json string to dict
d = json.loads(data.decode())
Here's an example notebook
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With