Skip to content

Instantly share code, notes, and snippets.

@shanehh
Last active November 17, 2021 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanehh/b1b382769b42952e4b9de6a161e7745b to your computer and use it in GitHub Desktop.
Save shanehh/b1b382769b42952e4b9de6a161e7745b to your computer and use it in GitHub Desktop.
import pyperclip
import json
def object2json_and_copy_it_to_clipboard(obj):
"""
convert any object jsonable(if need), and dumps it
copy to clipboard
"""
if hasattr(obj, "__dict__"):
obj = obj.__dict__
result = json.dumps(obj, ensure_ascii=False, indent=2)
pyperclip.copy(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment