SelectToken() with parenthesis in jToken throwing "Unexpected character while parsing path indexer" error

1

I'm trying to deserialize and parse a JsonObj

{ "obj": [
  {
    "name": "Kelly",
    "calculation": {
         "reff" : "apply(stringa/stringb)"
     },
    "value": "Number",
   }
  ]
}
string jsonString = JsonConvert.SerializeObject(jsonObj);
JObject parsedObj = JObject.Parse(jsonString );
var reffTokens = parsedObj.SelectTokens("$..reff");
foreach (JToken token in reffTokens.ToArray())
{
    var calculatedToken = parsedObj.SelectToken(token.ToString());   
}

I get this error:

Newtonsoft.Json.JsonException
HResult=0x80131500
Message=Unexpected character while parsing path indexer:
Source=Newtonsoft.Json

If I remove the braces and have the calculation part as

"calculation": {
  "reff" : "stringa/stringb"
},

then it works fine. any suggestion on how to deserialize and parse JObject for parentheses? Thanks!

c#
json.net
jsonpath
asked on Stack Overflow Jan 31, 2021 by ICoder • edited Jan 31, 2021 by dbc

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0