I have a Perl (.pm) file that I've been trying to get into a JSON representation so that I can then search for keywords inside of it.
The directory for my script is /Devices/bin/script.py. The directory where the .pm file lives in one level up, so /Devices/Devices.PM. Devices.PM is just a static file containing data structured as dictionaries and lists like so:
mylist = (
blah => {
other =9,
houses => 1,
etc => [
{ etc => '5',
ppl => '3,
things => "etc",
animals => [ 'blah-228', 'blah-229' ]
},
{ etc => '9',
ppl => '5',
things => "22",
animals => [ 'blah-2', 'blah-5' ]
},
],
partner => 'ets',
location => 'wherever',
},
blah => {
ppl => 6,
place => 101,
things => 'etc',
animals => 'whatever',
},
I have:
os.chdir("..")
with open('Devices.pm', 'r') as f:
json_obj = json.dumps(f)
print json_obj
but I keep getting TypeError: <open file 'SwitchConfig.pm', mode 'w' at 0x10c1f69c0> is not JSON serializable. I have tried this several ways with no luck, including json.dump(s). I keep getting different errors. Am I not understanding my .pm file structure correctly in order to turn it into a JSON representation?
f.read()