Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended to_json() to support sort key #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions treelib/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,9 +858,9 @@ def to_dict(self, nid=None, key=None, sort=True, reverse=False, with_data=False)
{ntag: {"data": self[nid].data}}
return tree_dict

def to_json(self, with_data=False, sort=True, reverse=False):
def to_json(self, with_data=False, sort=True, reverse=False, key=None):
"""To format the tree in JSON format."""
return json.dumps(self.to_dict(with_data=with_data, sort=sort, reverse=reverse))
return json.dumps(self.to_dict(with_data=with_data, sort=sort, reverse=reverse, key=key))

def to_graphviz(self, filename=None, shape='circle', graph='digraph'):
"""Exports the tree in the dot format of the graphviz software"""
Expand Down