I am using Python. I need to gather the content of js object while maintaining the values’ type.
for example I have a js file with the next content
const rules = {
force_update_cache: true,
country: 'gb',
override_headers: {
'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1',
},
navigate_opt: {wait_until: ['domcontentloaded'], timeout: 60*SEC},
}
I want to extract the keys and values of rules while maintaining the original type of the values.
I regexed my way to read only the keys and values without the "const rules {, }".
I tried using ast.literal_eval but it doesn’t work propely.
I expect to get evantually a dictionary with the keys, and values with their original type.
string.
number.
integer.
object.
array.
boolean.
null.
Is there a solution for that?
2
Answers
maybe you can try this