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"]
?
Asked
Active
Viewed 2,926 times
9
![](../../users/profiles/2380702.webp)
xor
- 3,583
- 1
- 21
- 32
2 Answers
11
Unfortunately this is not currently possible in jmespath.
![](../../users/profiles/5314382.webp)
Jordon Phillips
- 11,056
- 3
- 31
- 39
-
1I 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
![](../../users/profiles/975123.webp)
mekazu
- 2,015
- 3
- 18
- 20