I am trying to create a python script which can parse the following type of log entry which comprises of keys and values. For each key, there may or may not be another nested pair of keys and values. An example is as below. THe depth of the nesting can vary depeding on the log i get so it has to be dynamic. THe depth is however encapsulated with braces.
The string I will have with keys and values are something like this:
Countries = {
"USA" = 0;
"Spain" = 0;
Connections = 1;
Flights = {
"KLM" = 11;
"Air America" = 15;
"Emirates" = 2;
"Delta" = 3;
};
"Belgium" = 1;
"Czech Republic" = 0;
"Netherlands" = 1;
"Hungary" = 0;
"Luxembourg" = 0;
"Italy" = 0;
};
THe data above can have multiple nests as well. I would like to write a function that will parse through this and put it in an array of data (or similar) such that I could get a the value of a specific key like:
print countries.belgium
value should be printed as 1
likewise,
print countries.flights.delta
value should be printed as 3.
Note that the input doesnt need to have quotes in all the keys (like connections or flights).
Any pointers to what I can start with. Any python libraries that can already do some parsing like this?