I have the following sample data that are stored in a file:
[
{ "keys": ["val1", "val2"], "args": { "arg1": "val1", "arg2": "val2" } },
{ "keys": ["val1", "val2", "val3"], "args": { "arg": "val" } },
{ "keys": ["val"], "args": {} }
]
As you may realise, this is a list of dictionaries. Each dictionary has key keys contains arbitrary length of list and key args contains a dictionary
How could I parse this sample data back into Python object
with open('file_name') as file:
source = file.read()
data = how_to_parse(source)
for arr in data:
print(arr)
# Expected result
# { "keys": ["val1", "val2"], "args": { "arg1": "val1", "arg2": "val2" } }
# { "keys": ["val1", "val2", "val3"], "args": { "arg": "val" } }
# { "keys": ["val"], "args": {} }
pyparsing. I'd like to see an example using that library :)