9

In an aws cli jmespath query, with for example the output ["a","a","b","a","b"], how do i extract the unique values of it to get ["a","b"]?

xor
  • 3,583
  • 1
  • 21
  • 32

2 Answers2

11

Unfortunately this is not currently possible in jmespath.

Jordon Phillips
  • 11,056
  • 3
  • 31
  • 39
  • 1
    I would argue that jmespath is grep, not gawk. It just provides a selection of data. That is it's job. Processing json is someone else's business! :-) Now what that other tool should be is another question and I think the answer depends on context. – Max Murphy Feb 07 '17 at 12:41
3

It's not what you asked for but I've used the following:

aws ... | jq -r ".[]" | sort | uniq

This will convert ["a", "a", "b", "a"] to:

a
b
mekazu
  • 2,015
  • 3
  • 18
  • 20