Segment.Serialization.JsonObject – Critical Serialization Bug
Describe the Bug
There is a critical JSON serialization defect in Segment.Serialization.JsonObject.
The serializer produces invalid JSON when serializing Nullable<T> fields, resulting in malformed fragments such as:
instead of:
This breaks JSON format and causes Segment’s ingestion pipeline to silently drop events.
Our custom Rust implementation revealed the issue by producing correct JSON, making the discrepancy visible.
To Reproduce
- Download the reproduction project:
https://github.com/NickKhalow/JsonBugReproSegment
- Run the test suite.
- Observe malformed JSON output produced by
JsonObject when handling nullable fields.
Example of the broken output:
{"scene_hash": null,"old_parcel": "(NaN, NaN)","is_empty_scene": ,"new_parcel": "(1, -1)"}
Notice "is_empty_scene": , - the value is missing entirely.
Expected Behavior
JsonObject should correctly serialize Nullable<T> values:
- Nullable
- Nullable
- Nullable
Expected valid JSON:
or:
but never:
This violates the JSON specification and corrupts the payload.
Platform
- Library: Segment.Serialization.JsonObject
- Version: In production where the critical bug was found - 2.4.2 , repro project with the latest version at the moment - 2.5.3
- Platform: .NET and Unity
- Integrations: None (reproduces in isolation)
Additional Context
The bug is due to incorrect handling of Nullable<T> inside JsonObjectConverter.
When a nullable value is null, the serializer emits nothing, leaving a dangling comma and creating invalid JSON.
The silently ignore malformed payloads, this issue resulted in consistent unnoticed loss of analytics events.
Segment.Serialization.JsonObject – Critical Serialization Bug
Describe the Bug
There is a critical JSON serialization defect in
Segment.Serialization.JsonObject.The serializer produces invalid JSON when serializing
Nullable<T>fields, resulting in malformed fragments such as:"is_empty_scene": ,instead of:
This breaks JSON format and causes Segment’s ingestion pipeline to silently drop events.
Our custom Rust implementation revealed the issue by producing correct JSON, making the discrepancy visible.
To Reproduce
https://github.com/NickKhalow/JsonBugReproSegment
JsonObjectwhen handling nullable fields.Example of the broken output:
{"scene_hash": null,"old_parcel": "(NaN, NaN)","is_empty_scene": ,"new_parcel": "(1, -1)"}Notice
"is_empty_scene": ,- the value is missing entirely.Expected Behavior
JsonObjectshould correctly serializeNullable<T>values:Expected valid JSON:
or:
but never:
"is_empty_scene": ,This violates the JSON specification and corrupts the payload.
Platform
Additional Context
The bug is due to incorrect handling of
Nullable<T>insideJsonObjectConverter.When a nullable value is
null, the serializer emits nothing, leaving a dangling comma and creating invalid JSON.The silently ignore malformed payloads, this issue resulted in consistent unnoticed loss of analytics events.