def object_hook(d): """ Usage ----- >>> import simplejson as json >>> with open('file.json', 'r') as f: ... json.load(f, object_hook=object_hook) """ from segment import Segment from timeline import Timeline from annotation import Annotation from transcription import Transcription if PYANNOTE_JSON_SEGMENT in d: return Segment.from_json(d) if PYANNOTE_JSON_TIMELINE in d: return Timeline.from_json(d) if PYANNOTE_JSON_ANNOTATION in d: return Annotation.from_json(d) if PYANNOTE_JSON_TRANSCRIPTION in d: return Transcription.from_json(d) return d