I have a string that lists the properties of a request event.
My string looks like:
requestBody: {
propertyA = 1
propertyB = 2
propertyC = {
propertyC1 = 1
propertyC2 = 2
}
propertyD = [
{ propertyD1 = { propertyD11 = 1}},
{ propertyD1 = [ {propertyD21 = 1, propertyD22 = 2},
{propertyD21 = 3, propertyD22 = 4}]}
]
}
I have tried to replace the "=" with ":" so that I can put it into a JSON reader in python, but JSON also requires that key and value are stored in string with double quotes and a "," to separate each KV pair. This then became a little complicated to implement. What are some better approaches to parsing this into python dictionary with exactly the same structure (e.g. embedded dictionaries are also preserved)?
Question: If I were to write a full parser, what's the main pattern that I should tackle? Storing parenthesis in a stack until the parenthesis completes?
{}'s as some sort of nested object (such aspropertyC), and I understand multiple objects inside[]'s as an array of objects (as inpropertyD2). But what is intended when you have multiple properties inside []'s (as inpropertyD)? Should this really be an object in {}'s, with propertiespropertyD1andpropertyD2?propertyA?