I'm trying to split a string and get all json string that are in it
My string :
{"datas": {"type": "custom", "value": {"cat": "game", "func": "game", "args": ["action", "move", "ball", 0, 55, 223]}}}{"datas": {"type": "auth", "value": 0}}{"datas": {"type": "custom", "value": {"cat": "game", "func": "game", "args": ["action", "move", "ball", 0, 60, 218]}}}{"datas": {"type": "custom", "value": {"cat": "game", "func": "game", "args": ["action", "move", "ball", 0, 65, 213]}}}{"datas": {"type": "custom", "value": {"cat": "game", "func": "game", "args": ["action", "move", "ball", 0, 70, 208]}}}
My regex :
({.*})({.*)
But, the first group is the entire string without the last json string
{"datas": {"type": "custom", "value": {"cat": "game", "func": "game", "args": ["action", "move", "ball", 0, 55, 223]}}}{"datas": {"type": "auth", "value": 0}}{"datas": {"type": "custom", "value": {"cat": "game", "func": "game", "args": ["action", "move", "ball", 0, 60, 218]}}}{"datas": {"type": "custom", "value": {"cat": "game", "func": "game", "args": ["action", "move", "ball", 0, 65, 213]}}}
I want to get one by one like this :
{"datas": {"type": "custom", "value": {"cat": "game", "func": "game", "args": ["action", "move", "ball", 0, 55, 223]}}}
I don't know how to properly explain my problem, i hope you'll understand
Thanks for reading
**EDIT**: Finally, i didn't used regex. Here is my function :
def packet_to_jsonlist(s):
jsonlist = []
count = 0
current = 0
for i in range(0, len(s)):
if s[i] == '{':
count += 1
elif s[i] == '}':
count -= 1
if count == 0:
jsonlist.append(s[current:i+1])
current = i + 1
return jsonlist
dictusingjson.loads(...)and use normal dict/list operations.