I am trying to find and extract a pattern living in a json file. If I do this as a test, it finds and prints it, because the json.dumps makes it a string:
my_mi = {"_links": {"self": {"href": "/xx-beta/media/111ee111-1e11-11a1-b111/metadata"}}}
new = json.dumps(my_mi)
my_id = re.findall(r'\w{1,9}\-\w{1,5}\-\w{1,5}\-\w{1,5}\-\w{1,13}',
new)
print my_id
The problem is that when I try using it as a json file, I'm having trouble converting it in a way that it will work without throwing the error "TypeError: <open file 'resTwo.json', mode 'r' at 0x1109eee40> is not JSON serializable"
, which is what it does with the following:
with open ("resTwo.json", "r") as input_file:
new = json.dumps(input_file)
my_id = (re.findall(r'\w{1,9}\-\w{1,5}\-\w{1,5}\-\w{1,5}\-\w{1,13}', new))
print my_id
I thought json.dumps converted into a string so the regex would then work as in the test example?