mirror of
https://github.com/zyycn/codex-proxy-rs.git
synced 2026-11-13 08:06:41 +00:00
18 lines
461 B
Rust
18 lines
461 B
Rust
use serde_json::Value;
|
|
|
|
pub fn first_string(value: &Value, paths: &[&[&str]]) -> Option<String> {
|
|
paths.iter().find_map(|path| string_at(value, path))
|
|
}
|
|
|
|
pub fn string_at(value: &Value, path: &[&str]) -> Option<String> {
|
|
let mut current = value;
|
|
for segment in path {
|
|
current = current.get(*segment)?;
|
|
}
|
|
current
|
|
.as_str()
|
|
.map(str::trim)
|
|
.filter(|value| !value.is_empty())
|
|
.map(ToString::to_string)
|
|
}
|