INNER CODE UNIT · Python
try_parse_into_json
nordnet/next-api-v2-examples · python3/test_program.py:146
def try_parse_into_json(string):
"""
Try parsing the string into JSON objects. Return the unparsable
parts as buffer
"""
json_strings = string.split('\n')
for i in range(0, len(json_strings)):
try:
json_data = json.loads(json_strings[i])
print(">> JSON updates from public feed")
print(json.dumps(json_data, indent=4, sort_keys=True))
except:
## If this part cannot be parsed into JSON, It's probably not
## complete. Stop it right here. Merge the rest of list and
## return it, parse it next time
return ''.join(json_strings[i:])