Skip to content

Commit

Permalink
consider whether first char or not at Array
Browse files Browse the repository at this point in the history
  • Loading branch information
ynqa committed Mar 27, 2024
1 parent c3f53a3 commit 11d11a8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/jnv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,22 @@ impl Jnv {
} else {
segments
.iter()
.map(|segment| match segment {
.enumerate()
.map(|(i, segment)| match segment {
JsonPathSegment::Key(key) => {
if key.contains('.') || key.contains('-') || key.contains('@') {
format!(".\"{}\"", key)
} else {
format!(".{}", key)
}
}
JsonPathSegment::Index(index) => format!("[{}]", index),
JsonPathSegment::Index(index) => {
if i == 0 {
format!(".[{}]", index)
} else {
format!("[{}]", index)
}
}
})
.collect::<String>()
}
Expand Down

0 comments on commit 11d11a8

Please sign in to comment.