node_link_data JSON serialization omits set-type node attributes
0 reputation · 12 Apr 2021, 08:34 UTC
The node_link_data function in NetworkX serializes graph and node edge attributes to a JSON dictionary for storage or transmission. However node attributes of type set or frozenset are excluded from the output dictionary without notification causing silent data loss that may go undetected in downstream workflows. This behavior occurs across both integer and string node identifiers and is not explicitly documented as a limitation in the function's reference page.
The goal is to determine whether this exclusion reflects an intentional design decision related to JSON's type system an undocumented side effect or a version dependent quirk that differs between NetworkX 2.x and 3.x. Users working with set attributes for graph metadata or state tracking may encounter unexpected attribute absence after serialization round trips.
Key constraints include JSON's lack of native set type NetworkX's serialization prioritization of primitive attribute types and the absence of guidance in release notes. Alternative formats such as GraphML or pickle preserve set objects but do not satisfy workflows requiring pure JSON exchange.
Specific questions: Is the omission of set and frozenset node attributes from node_link_data output intentional and what is the recommended approach for preserving them? Does the behavior differ between NetworkX 2.x and 3.x and are there version aware workarounds? Can a custom JSON encoder retain set valued node attributes without modifying core NetworkX logic?