Skip to content

Commit 82e3b77

Browse files
committed
feat(op): handle flat JSON escape dot syntax
1 parent 6a9cf4f commit 82e3b77

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/op/data.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ fn get_key(data: &Value, key: KeyType) -> Option<Value> {
227227
}
228228
}
229229

230+
fn split_path(path: &str) -> impl Iterator<Item = String> + '_ {
231+
let mut index = 0;
232+
return path
233+
.split(move |c: char| {
234+
if c == '.' && path.chars().nth(index - 1).unwrap() != '\\' {
235+
index += 1;
236+
return true;
237+
}
238+
index += 1;
239+
return false;
240+
})
241+
.map(|part| part.replace("\\.", "."));
242+
}
243+
230244
fn get_str_key<K: AsRef<str>>(data: &Value, key: K) -> Option<Value> {
231245
let k = key.as_ref();
232246
if k == "" {
@@ -235,9 +249,9 @@ fn get_str_key<K: AsRef<str>>(data: &Value, key: K) -> Option<Value> {
235249
match data {
236250
Value::Object(_) | Value::Array(_) | Value::String(_) => {
237251
// Exterior ref in case we need to make a new value in the match.
238-
k.split(".").fold(Some(data.clone()), |acc, i| match acc? {
252+
split_path(k).fold(Some(data.clone()), |acc, i| match acc? {
239253
// If the current value is an object, try to get the value
240-
Value::Object(map) => map.get(i).map(Value::clone),
254+
Value::Object(map) => map.get(&i).map(Value::clone),
241255
// If the current value is an array, we need an integer
242256
// index. If integer conversion fails, return None.
243257
Value::Array(arr) => i

0 commit comments

Comments
 (0)