code: def json_export(self, dest, fieldnames=None, encoding="UTF-8"):
          close_on_exit = False
          if isinstance(dest, basestring):
              if PY_3:
                  dest = open(dest, 'w', encoding=encoding)
              else:
                  dest = open(dest, 'w')
              close_on_exit = True
          try:
              if isinstance(fieldnames, basestring):
                  fieldnames = fieldnames.split()
              if fieldnames is None:
                  do_all(dest.write(_to_json(o)+'\n') for o in self.obs)
              else:
                  do_all(dest.write(json.dumps(ODict((f, getattr(o, f)) for f in fieldnames))+'\n') for o in self.obs)
          finally:
              if close_on_exit:
                  dest.close()