Skip to content

Commit

Permalink
Add support arrays without a property name to json path (e.g. $.[0])
Browse files Browse the repository at this point in the history
  • Loading branch information
r15ch13 committed May 8, 2017
1 parent 5d625c1 commit 45721fc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/json.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ function json_path([Object] $json, [String] $jsonpath, [String] $basename) {
}

# array detection
if($el -match "^(?<property>\w+)\[(?<index>\d+)\]$") {
if($el -match "^(?<property>\w+)?\[(?<index>\d+)\]$") {
$property = $matches['property']
$result = $result.$property[$matches['index']]
if($property) {
$result = $result.$property[$matches['index']]
} else {
$result = $result[$matches['index']]
}
return
}

Expand Down

0 comments on commit 45721fc

Please sign in to comment.