skip to Main Content

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


  1. On my guess, the obtained result means that currently processed JsonNode is "id": 3 only. You need to come back to the root of current JsonNode and get the "name" node.

    Login or Signup to reply.
  2. You’ll need to parse the JsonNode into a JsonObject and use the ContainsKey method.

    JsonObject jsObj = _node.AsObject();
    bool hasProperty = jsObj.ContainsKey("name");
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search