MCPcopy Create free account
hub / github.com/python-cmd2/cmd2 / to_json

Method to_json

cmd2/history.py:342–348  ·  view source on GitHub ↗

Convert this History into a JSON string for use in persistent history files.

(self)

Source from the content-addressed store, hash-verified

340 return results
341
342 def to_json(self) -> str:
343 """Convert this History into a JSON string for use in persistent history files."""
344 json_dict = {
345 History._history_version_field: History._history_version,
346 History._history_items_field: [hi.to_dict() for hi in self],
347 }
348 return json.dumps(json_dict, ensure_ascii=False, indent=2)
349
350 @staticmethod
351 def from_json(history_json: str) -> "History":

Callers 3

_persist_historyMethod · 0.80
test_history_to_jsonFunction · 0.80
test_history_from_jsonFunction · 0.80

Calls 1

to_dictMethod · 0.45

Tested by 2

test_history_to_jsonFunction · 0.64
test_history_from_jsonFunction · 0.64