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

Order of relationships written to JSON file may be different from the order in which they were read #20

Closed
SamuraiAku opened this issue Dec 30, 2022 · 4 comments

Comments

@SamuraiAku
Copy link
Owner

Read a JSON file, then write it back out to another JSON file, then read that second file. The order of entries the Relationships vector is different. It doesn't matter at all from a data model point of view, but why does it do that?

@hannahilea
Copy link
Contributor

When using JSON.jl, to get back the objects in order you can pass in a dicttype arg:

you can pass dicttype=DataStructures.OrderedDict to maintain the insertion order of the items in the object;

ref https://github.com/JuliaIO/JSON.jl

@hannahilea
Copy link
Contributor

(As I understand it, the reason is that the JSON spec says that objects are un-ordered collections, even though various implementations do provide functionality to read/write in ordered ways)

@SamuraiAku
Copy link
Owner Author

I use the orderedDict in SPDX.jl and it works well. I think the bug is in how I'm creating the relationship vector in my own code. Need to review more and document a good example case.

I care about the order because it allows for a user to read in a file, make some small modifications such as update the version and checksum, and then write it all back to file and only those changed elements show up in a git diff. If I don't use OrderedDict there's no guarantee that would happen.

@SamuraiAku
Copy link
Owner Author

I tried recreating the issue and I can't do it. It doesn't matter anymore since I've updated the internal compare functions so they can handle out of order vectors. Close it for now, reopen if I find the bug again and I think it's important.

@SamuraiAku SamuraiAku closed this as not planned Won't fix, can't repro, duplicate, stale Jan 17, 2024
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

No branches or pull requests

2 participants