Skip to content

Instantly share code, notes, and snippets.

@cikabo
Created September 1, 2022 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cikabo/f04836fdffe8d708dc899ed91c5f04fd to your computer and use it in GitHub Desktop.
Save cikabo/f04836fdffe8d708dc899ed91c5f04fd to your computer and use it in GitHub Desktop.
jq queries
jq ".ratedProducts | max_by(.annualSaving)" response_comparison_private_nodiscounts.json
jq '.ratedProducts | map(select(.productProperties[].propName == "ONLINE_PRODUCT" and .contractTermInfo.priceGuaranteeType == "GUARANTEE")) | length' response-temp.json
jq '.ratedProducts | map(select(.productProperties[].propName == "ONLINE_PRODUCT" and .contractTermInfo.priceGuaranteeType == "GUARANTEE")) | max_by(.annualSaving) | .annualSaving' response-temp.json
jq ".ratedProducts | max_by(.annualSaving) | .annualSaving" response-temp.json
jq '.ratedProducts | map(select(.productProperties[].propName == "ONLINE_PRODUCT" and .productProperties[].propName == "TOTAL_ACCOUNT" and .contractTermInfo.priceGuaranteeType == "GUARANTEE")) | max_by(.annualSaving)' "response gas wrong mainProductId 23-07-2021.json"
----
jq '.elements | map(select(.name=="one"))' jqtest.json
jq '.elements | map(select(.properties[].p2 == "y"))' jqtest.json
jq '.elements | map(select(.properties[].p2 == "y" and .properties[].p1 == "x"))' jqtest.json
---
echo '{
"t": [{
"name": "George",
"id": 20,
"email": [ "george@domain1.com" , "george@domain2.com" ]
}, {
"name": "Jack",
"id": 18,
"email": [ "jack@domain3.com" , "jack@domain5.com" ]
}, {
"name": "Joe",
"id": 19,
"email": [ "joe@domain.com" ]
}]
}' | jq -r '.t | (["ID","NAME"] | (., map(length*"-"))), (.[] | [.id, .name]) | @tsv'
pbpaste | jq -r '.t[] | [.id, .name] | @tsv'
jq -r '.records| (["Name","Id","CreatedDate","brandId","mainId"] | (., map(length*"-"))), (.[] | [.Name, .Id, .CreatedDate, .brandId__c, .mainId__c, .mainAssociationId__c]) | @tsv'
cat aws_eu-central-1_instances.json | jq -r '.Reservations | map(select(.Instances[].State.Code == 16)) | (.[] | [.Instances[].InstanceType, .Instances[].Placement.AvailabilityZone]) | @tsv' | pbcopy
cat aws_eu-central-1_volumes.json | jq -r '.Volumes | map(select(.State=="in-use")) | length'
cat aws_eu-central-1_volumes.json | jq -r '.Volumes | map(select(.State=="in-use")) | (.[] | [.VolumeType, .Size]) | @tsv' | pbcopy
for task in `aws ec2 describe-regions --output text | cut -f4`; do echo -e "\nListing Instances in region:'$region'..."; aws ec2 describe-instances --region $region | jq '.Reservations[] | ( .Instances[] | [.State.Name, .KeyName, .InstanceType, .Placement.AvailabilityZone]) | @tsv' >> aws-instances.txt; done
for task in `aws ecs list-tasks --cluster "arn:aws:ecs:eu-central-1:546289415761:cluster/tatatu-ecs-stage" --output text | cut -f2`; do aws ecs describe-tasks --cluster "arn:aws:ecs:eu-central-1:546289415761:cluster/tatatu-ecs-stage" --tasks "$task" | jq '(.tasks[] | [.group, .cpu, .memory, .availabilityZone]) | @tsv' >> aws-ecs-stage.txt; done
cat ~/Documents/jira-updated.json | jq -r '.issues[] | [.fields.summary, .fields.parent.fields.summary]'
cat ~/Documents/jira-updated.json | jq -r '[.issues[] | .fields.parent?.fields.summary] | unique'
curl --silent --location -g --request GET 'https://tatatuproject.atlassian.net/rest/api/3/search?jql=updatedDate%20%3E%20startOfWeek(-1)%20AND%20updatedDate%20%3C%20startOfWeek()%20ORDER%20BY%20cf[10014]%20ASC,%20created%20DESC&maxResults=500' --header 'Authorization: Basic Ym9qYW5AdGF0YXR1LmNvbTpJeWpvbHpYb2pXc1I3RlZaZjNiV0E4NDU=' | jq -r '[.issues[] | .fields.parent?.fields.summary] | unique'
cat ~/moderation.json | jq -r '.result[] | select(.user.id == "6235e5d7cb2f08701d7ea243")'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment