Is there a way to navigate a JSON safely?
Given this JSON,
{
"foo": {
"bar": {
"baz": "quz"
}
}
}
I'd like to navigate it safely similar to the line below without creating types for all of them.
string value1 = jObj.foo?.bar?.baz ?? "default";
// value1 == "quz"
string value2 = jObj.foo?.abc?.def ?? "default";
// value2 == "default"
I might be able to write an extension method with this signature but please let me know if there is an easier way for the safe navigation.
string value = jObj.Value(
"foo.bar?.baz?[1].qux",
"default"
);