The settings file is represented by an in-memory JSON document:
JsonNode _jsonObj
_jsonObj is the persistence source of truth. The runtime Settings object is the app-facing state. Generated descriptors connect the two.
Plain serialization has several problems for settings:
- it replaces whole object graphs
- it drops unknown keys
- it cannot express missing vs null vs present as easily
- it makes compatibility with older or newer app versions harder
- it can break MVVM references
Settings files behave more like user documents than DTO payloads.
VS Code's settings model is a useful reference point: user settings are updated by editing specific JSON paths, which preserves unmanaged keys and, in VS Code's text-editing model, comments.
Everywhere should adopt the same preservation principle for unknown keys. However, the first Settings Engine is based on JsonNode, so comments and duplicate property spelling are not preserved.
First-stage guarantee:
unknown JSON keys are preserved by default
Not guaranteed:
comments are preserved
duplicate object properties are preserved
formatting is preserved exactly
3rd/WritableJsonConfiguration is useful because it already has:
- a
JsonNodedocument field - path navigation
- subtree replacement
- flattened configuration data generation
- debounced saving
- atomic file write behavior
Settings Engine should reuse or extract these ideas, but it should not keep IConfigurationProvider.Data as the main model. Flattened string data may exist only as a temporary compatibility view.
read settings.json bytes
-> parse JsonNode
-> run migration if needed
-> keep _jsonObj
-> patch existing Settings object
-> emit diagnostics
Parsing should accept the same relaxed JSON behavior as the current settings path where practical:
- trailing commas
- comments skipped during parsing
- duplicate properties tolerated by the parser
The canonical writer does not need to reproduce comments or duplicate entries.
Runtime setting changes should update _jsonObj locally.
Settings object changed
-> descriptor resolves JSON path
-> serialize known property value to JsonNode
-> replace that known subtree
-> preserve unknown siblings unless prune policy is active
-> debounce and atomically write settings.json
For a serialized subtree, the whole marked subtree is replaced.
When a collection element or dictionary value type is marked as a serialized subtree, a descendant change replaces that element or value rather than the containing collection.
For normal patch-managed objects, only known changed paths should be replaced.
Runtime change notifications use ObjectObserverPath, an immutable array of typed
segments. A segment is either a CLR property, a collection index, or a dictionary
key. The path is never flattened with :: a dictionary key such as provider:key
remains one segment. Settings Engine resolves these CLR segments through the
descriptor and only then creates a JSON path, where object properties and array
indexes have different representations.
Unknown keys are preserved because _jsonObj remains the source document.
Example:
{
"Display": {
"Theme": "Dark",
"OldSettingFromPreviousVersion": true
}
}Changing Display.Theme should not remove OldSettingFromPreviousVersion unless Display or that specific subtree is marked with prune behavior.
Pruning is opt-in.
Prune should be used for:
- machine-owned generated maps
- flags dictionaries where stale keys are harmful
- strict schema objects
- temporary migration output sections
Prune should not be the default for user-facing settings sections.
File writes should be atomic:
- serialize to memory
- write to a temporary file
- flush
- replace the target file
Major migrations should keep a pre-migration backup or history snapshot before writing cleaned settings JSON.
Settings Engine should collect diagnostics for:
- parse failure
- migration fallback
- scalar conversion failure
- serialized subtree failure
- unknown member errors for strict sections
- write failure
Diagnostics are required for a future settings sync page and are useful even before sync exists.