quinnj / JSON3.jl

Other
214 stars 47 forks source link

Preserve struct ordering when pretty-printing #195

Closed FedorChervyakov closed 2 years ago

FedorChervyakov commented 2 years ago

Fixes #192.

In this PR we rewrite the pretty function to parse the input as a JSON3.Object and add a couple of tests for the pretty function.

By parsing the input string as JSON3.Object and passing it recursively to pretty, we preserve field ordering.

New tests check that ordering of nested structs and NamedTuples is preserved. Also, this PR wraps tests related to pretty in pretty.jl testset.

quinnj commented 2 years ago

This looks to be headed in a decent direction. It does make me wonder though if we should just take a different approach all together w/ pretty printing and parse the input as a JSON3.Object first and then recursively print it out in a pretty way. That would preserve the ordering and probably end up being a simple implementation. But it's been long enough since I wrote this that I may have already tried that and it didn't work for some other reason.

FedorChervyakov commented 2 years ago

This looks to be headed in a decent direction. It does make me wonder though if we should just take a different approach all together w/ pretty printing and parse the input as a JSON3.Object first and then recursively print it out in a pretty way. That would preserve the ordering and probably end up being a simple implementation. But it's been long enough since I wrote this that I may have already tried that and it didn't work for some other reason.

Cool, it does make sense to parse as JSON3.Object first, I'll try to rewrite pretty using this approach.

codecov[bot] commented 2 years ago

Codecov Report

Merging #195 (06040bd) into main (da3ca85) will decrease coverage by 0.04%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #195      +/-   ##
==========================================
- Coverage   88.83%   88.78%   -0.05%     
==========================================
  Files           9        9              
  Lines        1693     1650      -43     
==========================================
- Hits         1504     1465      -39     
+ Misses        189      185       -4     
Impacted Files Coverage Δ
src/pretty.jl 91.83% <100.00%> (+0.53%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update da3ca85...06040bd. Read the comment docs.