Open Daniel15 opened 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).
So I had a think about what would be needed:
winnow
parsing library, as that is already in use for parsing the configuration script. Keeps the number of dependencies down (which help with compile time and binary size)language
directive in the chezmoi_modify_manager config that selected the processing pipeline to use, along with some tweaks to which directives are valid for which file formats.
ignore
, remove
, add:remove
seems fairly obvious how to support for JSONset
and the currently existing transforms is fairly straight forward for scalars in JSONset
or add:hide
an array or object in JSON would require some thought, can be skipped initially, but lets avoid painting ourself into a corner with the design at least.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.
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