Repository navigation
fix(json): treat null attributes as omitted when decoding - #309
Merged
Merged
Conversation
Signed-off-by: zhanghao <112082360+zhanghao0806@users.noreply.github.com>
duglin
force-pushed
the
fix/json-null-attributes
branch
from
November 16, 2026 14:15
9faf5e6 to
3636b23
Compare
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the change to treat top-level null attributes as omitted during JSON decoding.
No open issues 🎉
What changed in this PR
Updates the core JSON decoder to treat top-level null attributes as omitted, aligning with CloudEvents JSON semantics. This addresses the decoding distinction related to #199 without changing Python object equality or in-memory validation.
Changes:
- Filters null envelope values before version detection, time parsing, and event construction.
- Adds regression coverage for automatic, explicit, and custom factories, while verifying that nested payload nulls, false values, and zeros are preserved.
| File | Description |
|---|---|
tests/test_core/test_format/test_json.py |
Tests null-attribute omission, factory handling, and payload preservation. |
src/cloudevents/core/formats/json.py |
Removes top-level null values before processing the JSON envelope. |
Review effort: Balanced
duglin
approved these changes
Nov 16, 2026
4 of 6 tasks
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.
Description
Treat JSON envelope attributes whose value is
nullas omitted before version detection, time parsing, and event construction. The core JSON reader previously passed them to validation (orisoparsefortime), rejecting JSON representations permitted by the specification.Related to the JSON decoding distinction discussed in #199. This does not change Python object equality or in-memory attribute validation.
Specification: https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/formats/json-format.md#22-type-system-mapping
Validation
pytest -q: 886 passed, 18 xfailed.Only top-level null values are removed; payload contents are preserved. Prepared with AI assistance; commits are signed off.