Skip to content

Instantly share code, notes, and snippets.

@psydvl
Last active September 28, 2023 17:29
Show Gist options
  • Save psydvl/5c40a1ddd5bcbd601fe3284e013d2c05 to your computer and use it in GitHub Desktop.
Save psydvl/5c40a1ddd5bcbd601fe3284e013d2c05 to your computer and use it in GitHub Desktop.
JMESPath strange behaviour
#!/usr/bin/env bash
go install github.com/jmespath-community/jp@latest
# shellcheck disable=SC2089
data='[{
"stack": "",
"branch": [
"one/",
"two/"
]
}
]'
echo "$data" | jp "[]"
echo "$data" | jp "[?stack=='']"
echo "$data" | jp "[] .branch[]"
echo "$data" | jp "[?stack==''].branch[]"
echo "$data" | jp "[] .branch[?starts_with(@, 'one')]"
echo "$data" | jp "[?stack==''].branch[?starts_with(@, 'one')]"

output

$ ./file.sh  
[
  {
    "branch": [
      "one/",
      "two/"
    ],
    "stack": ""
  }
]
[
  {
    "branch": [
      "one/",
      "two/"
    ],
    "stack": ""
  }
]
[
  "one/",
  "two/"
]
[
  "one/",
  "two/"
]
[
  [
    "one/"
  ]
]
Error evaluating JMESPath expression: invalid type for: [one/ two/], expected: []functions.JpType{"string"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment