Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an 'Exists' method to return a bool representing whether or not a key exists #14

Closed
kbirk opened this issue Dec 9, 2015 · 1 comment

Comments

@kbirk
Copy link

kbirk commented Dec 9, 2015

I have a use case in which the existence of a particular attribute determines how I interact with the parsed JSON.

While the functionality is technically there:

// fields
_, exists = jsonParsed.Search("myProperty").Data().(float64)
if exists {

}
// objects
_, err = jsonParsed.Search("myObjProperty").ChildrenMap()
if err == nil {

}
// arrays
_, err = jsonParsed.Search("myArrProperty").Children()
if err == nil {

}

I think it would be convenient to have a simple and unified interface for doing so:

if jsonParsed.Exists("myPath", "to", "myProperty") {

} 
@pjebs pjebs mentioned this issue Jan 31, 2016
@Jeffail
Copy link
Owner

Jeffail commented Jan 31, 2016

Hey @kbirk,

I've just checked in 785f0ec. Thanks for raising this and sorry for the wait!

@Jeffail Jeffail closed this as completed Jan 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants