Skip to content

feat: make JSON edit without reserialize/reformat - #28

Open
jorenbroekema wants to merge 1 commit into
hvdb:masterfrom
jorenbroekema:prevent-reserialize
Open

feat: make JSON edit without reserialize/reformat#28
jorenbroekema wants to merge 1 commit into
hvdb:masterfrom
jorenbroekema:prevent-reserialize

Conversation

@jorenbroekema

Copy link
Copy Markdown
Contributor

Both JSON.parse/stringify and jq tools will parse JSON files by reserializing the whole tree.
It's quite challenging to then respect the original formatting of the file when we stringify the changes back to the file.

I looked up how VSCode tackles this challenge for the settings.json file, when you make changes to your settings via the UI.
They seem to be using jsonc-parser and use this trick to make robust edits without reserializing/reformatting the original document.

Alternative considered: regex string replace, but this seemed like a worse alternative in terms of maintainability and reliability/robustness. The downside of my proposal is introducing jsonc-parser as a dependency. However, it's an actively maintained package, backed by large organization (Microsoft), and has 0 dependencies itself and no vulnerabilities. Bundlesize of the entire thing is 6.5kb, I could check for the 2 methods we use assuming treeshaking, but it seems to not be as relevant for a devtools used only in pipelines/extensions/actions.

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

Successfully merging this pull request may close these issues.

1 participant