Edit a config file safely
This guide changes one setting in a JSON config file without touching anything else in it: you find the setting, change its value, compare your version with the file on disk, and then save or undo. Your edits stay in a copy of the file until you save, so the file other programs read does not change before then.
Before you start
Section titled “Before you start”The file must be a JSON file in UTF-8, opened from disk, and up to 2 GiB. NDJSON files, compressed files, and pasted or fetched documents open read-only; see What you can edit.
The steps use this file, saved as config.json:
{ "server": { "host": "0.0.0.0", "port": 8080 }, "logging": { "level": "info" }, "features": ["search", "export"]}Close the file in other programs before you save; see Saving replaces the original.
Find the setting
Section titled “Find the setting”Open config.json with Ctrl+O. Press Ctrl+P, type port, and press Enter on $.server.port. The tree expands server and selects port. See Go to a path.
Change the value
Section titled “Change the value”-
With
portselected, press F2. The value becomes an editable box. -
Type
8081and press Enter.
The tree shows "port": 8081, and a dot on the tab means the file has unsaved edits. The file on disk still says 8080.
To change several fields at once, use the subtree editor. To rename a key or add and remove members, see Rename, insert, and delete.
Check the change
Section titled “Check the change”The Compare view shows every difference between your version and the file on disk.
-
Click the top row of the tree,
{3}, so that the comparison covers the whole document. The click also collapses the tree; that does not matter here. -
Select Compare in the view switcher.
-
Select Compare with file… and choose
config.json, the file you are editing.
Your version is on the left and the file on disk on the right. The Patches list shows one difference: replace at /server/port. A difference you did not expect means an edit went wrong; undo it before you save. See Compare view.
Save or undo
Section titled “Save or undo”- Save: press Ctrl+S. JSON Digger replaces
config.jsonwith your version in one step and shows “Saved.” The dot on the tab disappears. - Undo: press Ctrl+Z to undo the last edit, before you save.
- Drop every edit: choose File → Discard Edits and confirm with Discard.
If you close the tab first, JSON Digger asks “Save changes to config.json?” with Save, Discard and Close, and Cancel. If it closes unexpectedly, it offers to recover your edits the next time it starts. See Save, undo, and recover edits.
Next steps
Section titled “Next steps”- Edit values: string, number, and
nullvalues, and the subtree editor - Schema validation: check the file against a JSON Schema before you save
- Document lint: find duplicate keys in a config file