Filter output based on the existence of multiple key/value pairsApply multiple filters to retrieve ec2 instancesaws-cli - Filtering output with --query and --filterHow to combine two arrays (`keys` and `values`) into an object using JMESPath?Filter object by property and select with key in jmespathUsing keys from the json src doc in a multiselect hash with JmespathHow do i filter on ansible stat existence flags?Get value from key/value pair using jmespath when value is a numberQuerying multiple valuesMultiple searches with with json_query/jmespath filter in AnsibleNew to JMESPath -> filter array without key/value pairsFilter JSON object based on children keysHow to take key value pairs and turn them into an array of objects using JMESPath
antonym of "billable"
Non-visual Computers - thoughts?
How to find out the average duration of the peer-review process for a given journal?
Is there any way to keep a player from killing an NPC?
Compelling story with the world as a villain
Is for(( ... )) ... ; a valid shell syntax? In which shells?
Are there any elected officials in the U.S. who are not legislators, judges, or constitutional officers?
If the first law of thermodynamics ensures conservation of energy, why does it allow systems to lose energy?
Are the players on the same team as the DM?
Architectural feasibility of a tiered circular stone keep
Why does The Ancient One think differently about Doctor Strange in Endgame than the film Doctor Strange?
Handling Disruptive Student on the Autistic Spectrum
How to make Ubuntu support single display 5120x1440 resolution?
Why is my Earth simulation slower than the reality?
Avoiding racist tropes in fantasy
How can I unambiguously ask for a new user's "Display Name"?
Does travel insurance for short flight delays exist?
French abbreviation for comparing two items ("vs")
Why did MS-DOS applications built using Turbo Pascal fail to start with a division by zero error on faster systems?
Anatomically Correct Whomping Willow
Are modern clipless shoes and pedals that much better than toe clips and straps?
Was it ever possible to target a zone?
Do they have Supervillain(s)?
Confirming resignation after resignation letter ripped up
Filter output based on the existence of multiple key/value pairs
Apply multiple filters to retrieve ec2 instancesaws-cli - Filtering output with --query and --filterHow to combine two arrays (`keys` and `values`) into an object using JMESPath?Filter object by property and select with key in jmespathUsing keys from the json src doc in a multiselect hash with JmespathHow do i filter on ansible stat existence flags?Get value from key/value pair using jmespath when value is a numberQuerying multiple valuesMultiple searches with with json_query/jmespath filter in AnsibleNew to JMESPath -> filter array without key/value pairsFilter JSON object based on children keysHow to take key value pairs and turn them into an array of objects using JMESPath
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Using JMESPath, is it possible to filter output based on the existence of multiple key/value pairs within the input?
From the example JSON below, what I'd like to do is extract only the objects that contain these key/value pairs within Tags
-
Environment / ABC
Project / Project2
The closest I can get is to select a single matching Tag, but I require the rest of the object too, and I also need to match against the other key/value pair -
Stacks[*].Tags[?Key=='Environment' && Value=='ABC']
Here is some exaple JSON input -
"Stacks": [
"StackId": "abc123",
"Tags": [
"Value": "Project 1",
"Key": "Project"
,
"Value": "ABC",
"Key": "Environment"
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack1",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
,
"StackId": "xyz123",
"Tags": [
"Value": "Project 1",
"Key": "Project"
,
"Value": "XYZ",
"Key": "Environment"
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack2",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
,
"StackId": "asd123",
"Tags": [
"Value": "Project 2",
"Key": "Project"
,
"Value": "ABC",
"Key": "Environment"
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack3",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
]
And here is the output that I require -
"StackId": "asd123",
"Tags": [
"Value": "Project 2",
"Key": "Project"
,
"Value": "ABC",
"Key": "Environment"
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack3",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
jmespath
add a comment |
Using JMESPath, is it possible to filter output based on the existence of multiple key/value pairs within the input?
From the example JSON below, what I'd like to do is extract only the objects that contain these key/value pairs within Tags
-
Environment / ABC
Project / Project2
The closest I can get is to select a single matching Tag, but I require the rest of the object too, and I also need to match against the other key/value pair -
Stacks[*].Tags[?Key=='Environment' && Value=='ABC']
Here is some exaple JSON input -
"Stacks": [
"StackId": "abc123",
"Tags": [
"Value": "Project 1",
"Key": "Project"
,
"Value": "ABC",
"Key": "Environment"
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack1",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
,
"StackId": "xyz123",
"Tags": [
"Value": "Project 1",
"Key": "Project"
,
"Value": "XYZ",
"Key": "Environment"
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack2",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
,
"StackId": "asd123",
"Tags": [
"Value": "Project 2",
"Key": "Project"
,
"Value": "ABC",
"Key": "Environment"
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack3",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
]
And here is the output that I require -
"StackId": "asd123",
"Tags": [
"Value": "Project 2",
"Key": "Project"
,
"Value": "ABC",
"Key": "Environment"
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack3",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
jmespath
add a comment |
Using JMESPath, is it possible to filter output based on the existence of multiple key/value pairs within the input?
From the example JSON below, what I'd like to do is extract only the objects that contain these key/value pairs within Tags
-
Environment / ABC
Project / Project2
The closest I can get is to select a single matching Tag, but I require the rest of the object too, and I also need to match against the other key/value pair -
Stacks[*].Tags[?Key=='Environment' && Value=='ABC']
Here is some exaple JSON input -
"Stacks": [
"StackId": "abc123",
"Tags": [
"Value": "Project 1",
"Key": "Project"
,
"Value": "ABC",
"Key": "Environment"
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack1",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
,
"StackId": "xyz123",
"Tags": [
"Value": "Project 1",
"Key": "Project"
,
"Value": "XYZ",
"Key": "Environment"
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack2",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
,
"StackId": "asd123",
"Tags": [
"Value": "Project 2",
"Key": "Project"
,
"Value": "ABC",
"Key": "Environment"
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack3",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
]
And here is the output that I require -
"StackId": "asd123",
"Tags": [
"Value": "Project 2",
"Key": "Project"
,
"Value": "ABC",
"Key": "Environment"
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack3",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
jmespath
Using JMESPath, is it possible to filter output based on the existence of multiple key/value pairs within the input?
From the example JSON below, what I'd like to do is extract only the objects that contain these key/value pairs within Tags
-
Environment / ABC
Project / Project2
The closest I can get is to select a single matching Tag, but I require the rest of the object too, and I also need to match against the other key/value pair -
Stacks[*].Tags[?Key=='Environment' && Value=='ABC']
Here is some exaple JSON input -
"Stacks": [
"StackId": "abc123",
"Tags": [
"Value": "Project 1",
"Key": "Project"
,
"Value": "ABC",
"Key": "Environment"
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack1",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
,
"StackId": "xyz123",
"Tags": [
"Value": "Project 1",
"Key": "Project"
,
"Value": "XYZ",
"Key": "Environment"
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack2",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
,
"StackId": "asd123",
"Tags": [
"Value": "Project 2",
"Key": "Project"
,
"Value": "ABC",
"Key": "Environment"
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack3",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
]
And here is the output that I require -
"StackId": "asd123",
"Tags": [
"Value": "Project 2",
"Key": "Project"
,
"Value": "ABC",
"Key": "Environment"
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack3",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
jmespath
jmespath
asked Jan 6 '17 at 10:13
David GardDavid Gard
4,82721 gold badges68 silver badges140 bronze badges
4,82721 gold badges68 silver badges140 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can use nested filters:
Stacks[? Tags[? Value=='ABC' && Key=='Environment']]
Brilliant, thanks. For completeness, I usedStacks[? Tags[? Value=='ABC' && Key=='Environment'] && Tags[? Value=='Project' && Key=='Project2']]
and it's working like a charm.
– David Gard
Jan 10 '17 at 11:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f41503405%2ffilter-output-based-on-the-existence-of-multiple-key-value-pairs%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use nested filters:
Stacks[? Tags[? Value=='ABC' && Key=='Environment']]
Brilliant, thanks. For completeness, I usedStacks[? Tags[? Value=='ABC' && Key=='Environment'] && Tags[? Value=='Project' && Key=='Project2']]
and it's working like a charm.
– David Gard
Jan 10 '17 at 11:51
add a comment |
You can use nested filters:
Stacks[? Tags[? Value=='ABC' && Key=='Environment']]
Brilliant, thanks. For completeness, I usedStacks[? Tags[? Value=='ABC' && Key=='Environment'] && Tags[? Value=='Project' && Key=='Project2']]
and it's working like a charm.
– David Gard
Jan 10 '17 at 11:51
add a comment |
You can use nested filters:
Stacks[? Tags[? Value=='ABC' && Key=='Environment']]
You can use nested filters:
Stacks[? Tags[? Value=='ABC' && Key=='Environment']]
answered Jan 10 '17 at 9:58
gdyuldingdyuldin
861 bronze badge
861 bronze badge
Brilliant, thanks. For completeness, I usedStacks[? Tags[? Value=='ABC' && Key=='Environment'] && Tags[? Value=='Project' && Key=='Project2']]
and it's working like a charm.
– David Gard
Jan 10 '17 at 11:51
add a comment |
Brilliant, thanks. For completeness, I usedStacks[? Tags[? Value=='ABC' && Key=='Environment'] && Tags[? Value=='Project' && Key=='Project2']]
and it's working like a charm.
– David Gard
Jan 10 '17 at 11:51
Brilliant, thanks. For completeness, I used
Stacks[? Tags[? Value=='ABC' && Key=='Environment'] && Tags[? Value=='Project' && Key=='Project2']]
and it's working like a charm.– David Gard
Jan 10 '17 at 11:51
Brilliant, thanks. For completeness, I used
Stacks[? Tags[? Value=='ABC' && Key=='Environment'] && Tags[? Value=='Project' && Key=='Project2']]
and it's working like a charm.– David Gard
Jan 10 '17 at 11:51
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f41503405%2ffilter-output-based-on-the-existence-of-multiple-key-value-pairs%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown