def load(self, bytes, base_url=None): """ Takes a bytestring and returns a document. """ try: data = json.loads(bytes.decode('utf-8')) except ValueError as exc: raise ParseError('Malformed JSON. %s' % exc) doc = _parse_document(data, base_url) if not isinstance(doc, Document): raise ParseError('Top level node must be a document.') return doc