code: def to_json(fn, obj):
      
      with open(fn, 'w') as f:
          json.dump(obj, f, cls=OperatorEncoder, indent=2, ensure_ascii=False)
      return fn
docs: Convenience method to save pyquil.operator_estimation objects as a JSON file.
  
      See :py:func:`read_json`.