Skip to content

Commit c6faf0d

Browse files
committed
Add has_key to JsonValue, closes #86
1 parent 3c20cc3 commit c6faf0d

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/value/mod.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,18 @@ impl JsonValue {
380380
}
381381

382382
/// Works on `JsonValue::Array` - checks if the array contains a value
383-
pub fn contains<T>(&self, item: T) -> bool where T: Into<JsonValue> {
383+
pub fn contains<T>(&self, item: T) -> bool where T: PartialEq<JsonValue> {
384384
match *self {
385-
JsonValue::Array(ref vec) => {
386-
vec.contains(&item.into())
387-
},
388-
_ => false
385+
JsonValue::Array(ref vec) => vec.iter().any(|member| item == *member),
386+
_ => false
387+
}
388+
}
389+
390+
/// Works on `JsonValue::Object` - checks if the object has a key
391+
pub fn has_key(&self, key: &str) -> bool {
392+
match *self {
393+
JsonValue::Object(ref object) => object.get(key).is_some(),
394+
_ => false
389395
}
390396
}
391397

0 commit comments

Comments
 (0)