mirror of
https://github.com/fluencelabs/jsonpath
synced 2025-06-12 23:51:26 +00:00
Return Option<Value> from fun on replace_with to all user to return None (remove the value and not replace with Null)
This commit is contained in:
@ -56,24 +56,24 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn replace_fun(v: Value, fun: &js_sys::Function) -> Value {
|
||||
fn replace_fun(v: Value, fun: &js_sys::Function) -> Option<Value> {
|
||||
match JsValue::from_serde(&v) {
|
||||
Ok(js_v) => match fun.call1(&JsValue::NULL, &js_v) {
|
||||
Ok(result) => match into_serde_json(&result) {
|
||||
Ok(json) => json,
|
||||
Ok(json) => Some(json),
|
||||
Err(e) => {
|
||||
console_error!("replace_with - closure returned a invalid JSON: {:?}", e);
|
||||
Value::Null
|
||||
Some(Value::Null)
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
console_error!("replace_with - fail to call closure: {:?}", e);
|
||||
Value::Null
|
||||
Some(Value::Null)
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
console_error!("replace_with - invalid JSON object: {:?}", e);
|
||||
Value::Null
|
||||
Some(Value::Null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user