def __iter__(self): result = self.dicts if self.header is None: # determine fields header = list() for o in result: if hasattr(o, 'keys'): header.extend(k for k in o.keys() if k not in header) else: header = self.header yield tuple(header) # output data rows for o in result: row = tuple(o[f] if f in o else None for f in header) yield row
def __iter__(self): with self.source.open_() as f: result = json.load(f, *self.args, **self.kwargs) if self.header is None: # determine fields header = list() for o in result: if hasattr(o, 'keys'): header.extend(k for k in o.keys() if k not in header) else: header = self.header yield tuple(header) # output data rows for o in result: row = tuple(o[f] if f in o else None for f in header) yield row