Skip to content

Export json with id and add 'from_json' func - #239

Closed
dgercho wants to merge 6 commits into
caesar0301:masterfrom
dgercho:dev/105-from_json
Closed

Export json with id and add 'from_json' func#239
dgercho wants to merge 6 commits into
caesar0301:masterfrom
dgercho:dev/105-from_json

Conversation

@dgercho

@dgercho dgercho commented Jun 22, 2025

Copy link
Copy Markdown
Contributor

Changes:

  1. Added the node identifier (not presented when exporting to json format).
  2. Added the ability to load a json blob into a 'Tree' structure.
  3. Update the constant json outputs as part of the 'test_shallow_paste'.

@dgercho
dgercho requested a review from liamlundy as a code owner June 22, 2025 13:21
@dgercho
dgercho force-pushed the dev/105-from_json branch 4 times, most recently from 0ab26a7 to 3bd50b8 Compare June 22, 2025 14:19
@dgercho
dgercho force-pushed the dev/105-from_json branch from 3bd50b8 to 72c8f56 Compare June 22, 2025 14:22
@dgercho

dgercho commented Jul 6, 2025

Copy link
Copy Markdown
Contributor Author

@liamlundy @caesar0301
Hi, any updates regarding this PR?

@dgercho
dgercho force-pushed the dev/105-from_json branch 3 times, most recently from 04a5df8 to ea01eb2 Compare July 6, 2025 14:08
@dgercho
dgercho force-pushed the dev/105-from_json branch from ea01eb2 to cbbe171 Compare July 6, 2025 14:10
@cmoliverio

cmoliverio commented Feb 9, 2026

Copy link
Copy Markdown

When is this PR going to be integrated? Been half a year and this addition is quite small, but IMO critical. to_json needs to exist with a from_json counterpart, even if 1.8.0 rolls into 2.0.0 IMO. There is even a duplicate PR (#105) , and another PR that wants to add the identifier to the to_json, #123, so people clearly want this. . . I understand those are relatively easy to implement but this seems like a slam dunk that hasn't been dunking. @liamlundy

@liamlundy

Copy link
Copy Markdown
Collaborator

In order for this to not be a breaking change, can you change the default to_dict behavior to not return nid? Make sure all tests pass and this should be good to merge

@cmoliverio

Copy link
Copy Markdown

Hey @liamlundy , I believe I have come up with a solution that is the best of both worlds. It adds the optional parameter with_identifier to the functon to_dict and to_json. This makes it backwards compatible. This makes it fairly trivial to implement the from_json function that @dgercho has made but with a few changes.

Please see #244

@dgercho

dgercho commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@liamlundy Updated the PR as requested and added a new test for this functionality.

@dgercho

dgercho commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@liamlundy Can you re-run the CI?

@cmoliverio

cmoliverio commented Jul 3, 2026

Copy link
Copy Markdown

Hey @dgercho you can re-run the CI/CD by force pushing.

Also, the reason 3.9 fails is because the workflow needs to be fixed. Here is the fix: https://github.com/caesar0301/treelib/pull/244/changes

You could add that change and then make a new commit and it should pass :)

@dgercho

dgercho commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@liamlundy Done 🎉

@liamlundy

Copy link
Copy Markdown
Collaborator

@cmoliverio @dgercho this looks good. It looks like some code is duped between this and #244 but they also have unique patches. I'm happy to approve both but let me know how you want to approach the merge order.

@cmoliverio

cmoliverio commented Jul 8, 2026

Copy link
Copy Markdown

Respectfully, I believe the from_json() from this PR is inferior in one way: it uses the tag for both the tag and identifier when creating a new code.

This PR:

tree.create_node(tag=tag, identifier=tag, parent=parent_id, data=node_data)

#244:

tree.create_node(tag=tag, identifier=node_id, parent=parent_id, data=node_data)

I believe we need to consider the use case where a user needs to identify a node with two different names/methods.
This is why it becomes important to give the user the option to export to JSON with the identifier, which is also implemented in my PR. Otherwise we should just let the library handle the generation of a UUID (like normal). (I personally need this functionality in a project so I really want this)

@dgercho What are your thoughts on this slight improvement?

@dgercho

dgercho commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Go ahead @cmoliverio

@cmoliverio

Copy link
Copy Markdown

Apologies, do you mean you are on board with liam merging my PR?

@liamlundy

Copy link
Copy Markdown
Collaborator

Let's do this: can you @cmoliverio merge this branch into yours? The main component from this PR that I want to include is the unit test

@cmoliverio

Copy link
Copy Markdown

dgercho's branch was merged. #244 is ready to go.

@liamlundy

Copy link
Copy Markdown
Collaborator

Thanks @dgercho for your work on this! I approved #244

@liamlundy liamlundy closed this Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants