Created
June 22, 2020 17:15
-
-
Save bhuiyanmobasshir94/392e18d862ed1b060669cf14bf51ef55 to your computer and use it in GitHub Desktop.
log parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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