So I am writing a wrapper for JsonNode to easier extract json properties when there is no data-contract and I need to support a plethora of different values. But I am having some issues when it comes to reading an empty value. So either I am doing something wrong, or JsonNode is the wrong class to work with here.
My test-json is the following:
{
"id": 3,
"name": null
}
And I am doing different kind of queries against the JsonNode.
_node.HasProperty("id")
will return true, but
_node.HasProperty("name")
will return false.
So is there a way to achieve this?
Please advice.
2
Answers
On my guess, the obtained result means that currently processed
JsonNode
is"id": 3
only. You need to come back to the root of currentJsonNode
and get the "name" node.You’ll need to parse the
JsonNode
into aJsonObject
and use theContainsKey
method.