Check existence
pjebs opened this issue · 3 comments
This may be related to: #14
In your example:
value, ok = jsonParsed.Search("outter", "inner", "value1").Data().(float64)
// value == 10.0, ok == true
value, ok = jsonParsed.Path("does.not.exist").Data().(float64)
// value == 0.0, ok == false
The second example is actually ambiguous.
ok
could be false either because the path does not exist OR because the data could not be type asserted to float64.
Is there another way to just determine if the path exists -- irrespective of the data type or whether the type assertion failed.
I haven't checked code but perhaps this is it:
jsonParsed.Path("does.not.exist").Data() == nil
If the above code works, then maybe a nice convenience method: jsonParsed.Path("does.not.exist").Exists()