Store nil JSON assignments as null#10
Merged
Merged
Conversation
atdrendel
commented
Jun 25, 2026
Contributor
- Add removeValue(forKey:) for explicit dictionary key removal
- Distinguish missing optional JSON values from explicit NSNull comparisons
- Document and test nil subscript assignment behavior
- Add removeValue(forKey:) for explicit dictionary key removal - Distinguish missing optional JSON values from explicit NSNull comparisons - Document and test nil subscript assignment behavior
There was a problem hiding this comment.
Pull request overview
This PR adjusts JSON dictionary subscript semantics so assigning nil stores an explicit JSON null value (instead of removing the key), adds an explicit removeValue(forKey:) API for key removal, and updates tests/docs to cover the new behavior and null-vs-missing distinction.
Changes:
- Store
nildictionary subscript assignments asJSON.nullacrossJSONandJSON?subscripts. - Add
removeValue(forKey:)to explicitly remove keys from JSON dictionaries. - Add/extend tests and README guidance for
nilassignment behavior and distinguishing missing keys from explicitnull(includingNSNullcomparisons).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Tests/JSONTests/JSONTests.swift | Adds coverage for nil subscript assignment storing JSON.null, removeValue(forKey:), and NSNull comparison behavior. |
| Sources/JSON/JSON.swift | Implements nil-as-null subscript setters, adds removeValue(forKey:), and updates NSNull equality to distinguish missing vs explicit null. |
| README.md | Documents the new nil subscript assignment semantics and the new explicit key removal API. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.