Skip to content

Instantly share code, notes, and snippets.

@bhuiyanmobasshir94
Created June 22, 2020 17:15
Show Gist options
  • Save bhuiyanmobasshir94/392e18d862ed1b060669cf14bf51ef55 to your computer and use it in GitHub Desktop.
Save bhuiyanmobasshir94/392e18d862ed1b060669cf14bf51ef55 to your computer and use it in GitHub Desktop.
log parser
def extract_error_message(value, message = ''):
for k, v in value.items():
if isinstance(v,dict):
message += f'{k} -> '
message = extract_error_message(v, message)
else:
if isinstance(v,list):
message += f'{k} : {v[0]}, '
else:
message += f'{k} : {v}, '
return message
m = extract_error_message(
{"data":
{
"message": "Hi",
"card_info":
{
"error": [
"Card validation error, message: CVV length of Visa, MasterCard, Discover and JCB should be 3"
],
"Fail": "Failure"
},
"another": "check"
},
"SLast": "Second Last Check",
"Last": "Last Check"
})
print(m[:-2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment