Search code examples
vb.netjson.netlinq-to-json

How to use SelectToken with square brackets?


How can I get the value or make a SelectToken, if the Name of the JToken includes square brackets? tmpJToken.Value(Of String)("3/32[v]") or tmpJToken.SelectToken("3/32[v]")

Do I have to escape the square brackets?

The JSON looks like:

["BeginOfEnumerable",
  [
    {
        "Classification": [
            "/",
            "/Document/"
            
        ],
        "FieldValues": {
            "/0": "8854723",                
            "/3/32[v]": "1856929"                
        },
        "Key": "urn:key:Document:1856929"
    }
],
"EndOfEnumerable"]

Solution

  • use SelectToken with JSONPath.

    Dim result = tmpJToken.SelectToken("$..FieldValues.['/3/32[v]']")
    

    dotnetfiddle