VorpalBlade / chezmoi_modify_manager

Tools for chezmoi to handle mixed settings and state
GNU General Public License v3.0
40 stars 5 forks source link

JSON #131

Open Daniel15 opened 3 months ago

Daniel15 commented 3 months ago

Is your feature request related to a problem? Please describe.

Thank you for working on this useful project! I was wondering whether you'd consider adding support for JSON files?

Describe the solution you'd like

Initially it could be something basic, like just a list of paths to ignore.

Round-tripping JSON shouldn't be too difficult, and a lexer + parser that retains trivia should let you retain the same formatting on output.

Describe alternatives you've considered

N/A

Additional context

VorpalBlade commented 3 months ago

While I have not thought about json specifically, I did consider xml at one point. Json should be simpler than XML.

One thing that would be needed would be a format-preserving Json parser and serialiser (e.g. not change newlines, indentation, no reformatting numbers, etc). For INI files I wrote my own code for this, but I'd rather not for Json as it is a more complex format.

I also don't have a personal need for this, and this is a hobby project. So, contributions are welcome. If anyone is interested I'm willing to discuss the design (the first new format to support will be the hardest design-wise, as we need to make the code generic over the file format).

VorpalBlade commented 3 months ago

So I had a think about what would be needed:

JSON

Other formats

Side note about about XML (since I also considered this case): XML would be more complicated: you may not have unique keys, you can have text as siblings to nodes, you have attributes on nodes (not just contents) etc.

Side note about toml: toml_edit exists as a Rust library, but this is a DOM style library as far as I know. Not ideal since the merge and filter algorithms is written for a streaming approach.