Reputation: 15
I read a file from S3 Bucket using obj.get()['Body'].read()
and
this returned
b'[{ "version": "v1", "timeDelta": 0.0, "artist": "", "title": "text="Spot Block End" amgTrackId="9876543"", "timestamp": "1586453290376" }]'
I would like to extract the value of the timestamp key.
I stored a few .meta files in my s3 bucket, I need to check each of my .meta file has a timestamp
Upvotes: 0
Views: 101
Reputation: 536
This is not in json format. It seems like you need to escape the " in the title key
"title": "text=\"Spot Block End\" amgTrackId=\"9876543\""
Like this.
Maybe you can try to use regex to do it for you.
EDIT:
import json
import re
input = b'[{ "version": "v1", "timeDelta": 0.0, "artist": "", "title": "text="Spot Block End" amgTrackId="9876543"", "timestamp": "1586453290376" }]'
input = input.decode('utf-8')
match = re.findall('(?<=\"title\": \").*\"(?=\")',input)[0]
escaped_match = json.dumps(match)
input = input.replace(match,escaped_match[1:-1])
print(json.loads(input))
Take a look at this code, it's a bit ugly, but it works.
Hope it helps!
Upvotes: 1