Attempt to parse a json object from a buffer. If there is at least one object, return it and the rest of the buffer, otherwise return None.
(buffer)
| 20 | |
| 21 | |
| 22 | def json_splitter(buffer): |
| 23 | """Attempt to parse a json object from a buffer. If there is at least one |
| 24 | object, return it and the rest of the buffer, otherwise return None. |
| 25 | """ |
| 26 | buffer = buffer.strip() |
| 27 | try: |
| 28 | obj, index = json_decoder.raw_decode(buffer) |
| 29 | rest = buffer[json.decoder.WHITESPACE.match(buffer, index).end():] |
| 30 | return obj, rest |
| 31 | except ValueError: |
| 32 | return None |
| 33 | |
| 34 | |
| 35 | def json_stream(stream): |