I have some data that looks like YAML, but aint. Here is an example;
An instance of A
objectID=123
family=abc
An instance of A
objectID=234
family=bcd
List of 4 X elements:
An instance of X:
objectID=222
name=ccc
An instance of X:
objectID=333
And so on…
I need to find a way to make it looks more like this:
[
{'name': 'An instance of A',
'data': [
{'objectID': 123,
'family': 'abc'
}
]
},
...
I have tried to create some recursive function to parse this, but it ends up being a mess.
I’m not asking for a complete working example, but what is the best way to do this in python?
Self calling function? Using another lib (which I haven’t found yet)? Using another language to help me and embed the whole thing in python?
Use a stack, and push and pop items from it as you find more or fewer levels of indentation; each level on the stack holds the indentation depth and the entry: