#[cfg(feature = "jshift")]
mod imp {
use crate::error::{BrainError, Result};
use jshift::{find_value, mutate_value, parse_path};
pub fn update_json_field_inplace(
json_bytes: &mut Vec<u8>,
path_expr: &str,
new_value_bytes: &[u8],
) -> Result<()> {
let path = parse_path(path_expr);
mutate_value(json_bytes, &path, new_value_bytes)
.map_err(|e| BrainError::other(format!("jshift mutate failed: {e}")))?;
Ok(())
}
pub fn extract_json_field_slice<'a>(
json_bytes: &'a [u8],
path_expr: &str,
) -> Option<&'a [u8]> {
let path = parse_path(path_expr);
find_value(json_bytes, &path).ok()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn jshift_inplace_mutation() {
let mut json =
b"{\"node_id\": \"concept-1\", \"status\": \"draft\", \"weight\": 0.5}".to_vec();
update_json_field_inplace(&mut json, "status", b"\"published\"").unwrap();
let status = extract_json_field_slice(&json, "status").unwrap();
assert_eq!(status, b"\"published\"");
}
}
}
#[cfg(feature = "jshift")]
pub use imp::*;