JsonNode have no way to represent JSON null as object. Instead JsonNode represent JSON null as null reference: JsonNode.Parse("null") is null returns true. That cause some issues when passing such value as NpgsqlParameter.
When using non-generic NpgsqlParameter: new NpgsqlParameter { NpgsqlDbType = NpgsqlDbType.Jsonb, Value = JsonNode.Parse("null") } it cause exception: System.InvalidOperationException: Parameter '' cannot be null, DBNull.Value should be used instead. That is understandable as no type information associated with null reference.
With generic NpgsqlParameter: new NpgsqlParameter<JsonNode> { NpgsqlDbType = NpgsqlDbType.Jsonb, TypedValue = JsonNode.Parse("null") } it passes value as SQL NULL, but not as JSON null.
As I can see, there is no way to pass JSON null value by using JsonNode. There is no issue when JSON null is part of JSON array or JSON object. Only when JSON null is entire JSON document.
Not sure if current behavior could/should be changed from compatibility point of view, but it definitely should be documented.
JsonNodehave no way to represent JSONnullas object. InsteadJsonNoderepresent JSONnullasnullreference:JsonNode.Parse("null") is nullreturns true. That cause some issues when passing such value asNpgsqlParameter.When using non-generic
NpgsqlParameter:new NpgsqlParameter { NpgsqlDbType = NpgsqlDbType.Jsonb, Value = JsonNode.Parse("null") }it cause exception:System.InvalidOperationException: Parameter '' cannot be null, DBNull.Value should be used instead.That is understandable as no type information associated withnullreference.With generic
NpgsqlParameter:new NpgsqlParameter<JsonNode> { NpgsqlDbType = NpgsqlDbType.Jsonb, TypedValue = JsonNode.Parse("null") }it passes value as SQLNULL, but not as JSONnull.As I can see, there is no way to pass JSON
nullvalue by usingJsonNode. There is no issue when JSONnullis part of JSON array or JSON object. Only when JSONnullis entire JSON document.Not sure if current behavior could/should be changed from compatibility point of view, but it definitely should be documented.