Lets say I have an incoming string oversocket and it look like this
'text.....text {"foo": {"bar":100}} text {"bar":2} test {"foo"'
What is the best way/library to extract only the json objects out of the incoming string?
I have tried simplejson.JSONDecoder from simple json library. However, it is not only finding objects or I didn't know how to use it.
I have tried something like this so far
import simplejson as json
input_buffer = ""
def in_data(data):
input_buffer += data
try:
dict, idx = json.JSONDecoder().raw_decode(input_buffer)
except:
#handle exception in case nothing found
self.handle_input(dict) #send the dictionary for processing
input_buffer = input_buffer[idx:]