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

Deterministic parse and generate #206

Open
AndreaCrotti opened this issue May 23, 2024 · 3 comments
Open

Deterministic parse and generate #206

AndreaCrotti opened this issue May 23, 2024 · 3 comments

Comments

@AndreaCrotti
Copy link

AndreaCrotti commented May 23, 2024

Is there any possible way to make something like that work?
I have massive JSON files (on single lines so no spacing issues) and for annoying reasons, I have to regenerate exactly the same thing after I parse it.
It works more or less randomly, but I sometimes get the keys in the maps in a different order, is there any way to make that deterministic?

(def obj (cheshire.core/parse-string (slurp "myfile.json")))
(def full-string (slurp "myfile.json"))
(= full-string (cheshire.core/generate-string obj)) ;; false

It's probably just because parsing will generate non sorted maps, is there any way to make Cheshire use sorted maps?

@AndreaCrotti
Copy link
Author

I just tried one little change #207
but unfortunately that's not enough, it still does not work

@rap1ds
Copy link

rap1ds commented Sep 10, 2024

I have a bit similar use-case. I'm using cheshire for pretty-printing JSON.

So I'm reading the JSON from file and then using parse-stream and generate-string with pretty printing options, and the end result is a pretty printed JSON file but the order of the keys is changed. Would be nice if there was an option in Cheshire to keep the order of the keys.

@rap1ds
Copy link

rap1ds commented Sep 10, 2024

Related: #73

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