maciejhirsz / json-rust

JSON implementation in Rust
Apache License 2.0
563 stars 63 forks source link

Add `as_object` and `as_array` #173

Open MOZGIII opened 4 years ago

MOZGIII commented 4 years ago

Both as_object and as_array make sense, would be great to have them.

This is what I'm using currently:

pub(super) fn json_as_array(val: &JsonValue) -> Option<&Vec<JsonValue>> {
    match val {
        JsonValue::Array(val) => Some(val),
        _ => None,
    }
}

pub(super) fn json_as_object(val: &JsonValue) -> Option<&JsonObject> {
    match val {
        JsonValue::Object(val) => Some(val),
        _ => None,
    }
}