Skip to content

Commit

Permalink
Merge pull request #34 from ynqa/v0.2.x/fix-suggestion-at-array
Browse files Browse the repository at this point in the history
fix: consider whether first char or not at Array
  • Loading branch information
ynqa committed Mar 28, 2024
2 parents c3f53a3 + 11d11a8 commit 489421d
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 489421d

Please sign in to comment.