## Select dict fields of array of dicts
cat 256-colors.json | jq '.[] | {colorId, hexString, hsl, rgb, name}'
## Merge dic fields of array of dicts
## Read first item from {"Events":[]} & keep the hirearchy
cat data/ct-events.json | jq '.Events[0] | {Events: [.]}'JMESPath Tutorial
JMESPath Libraries
JMESPath Python Library
JMESPath Cheatsheet for AWS
# returns Events[].userIdentity.type
python jmes-term.py --query 'Events[].userIdentity.type'
# returns Events[].userIdentity.type top 5 based on [start:stop:step]
python jmes-term.py --query 'Events[:5].userIdentity.type'
# returns Events[].userIdentity.type last 5 based on [start:stop:step]
python jmes-term.py --query 'Events[-6:].userIdentity.type'
# returns Events[].userIdentity.type in reverse order
python jmes-term.py --query 'Events[::-1].userIdentity.type'
# returns type & accountId from userIdentity
python jmes-term.py --query "Events[?userIdentity.type == 'IAMUser'].{type: userIdentity.type, accountId: userIdentity.accountId}"Filter Array for item in a dictionary.
cat 256-colors.json | jq . | grep -A1 -B13 '"Olive"' | jq ' . | {colorId, hexString, hsl, rgb, name}'[{
"colorId": 3,
"hexString": "#808000",
"hsl": {"h": 60, "s": 100, "l": 25},
"rgb": { "r": 128, "g": 128, "b": 0 },
"name": "Olive"
}]## hexString -> hex
## hsl -> flatten array
## rgb -> flatten array
cat 256-colors.json | jq '[.[] | {colorId, name, hex: .hexString, hsl: [.hsl.h, .hsl.s, .hsl.l] | join(","), rgb: [.rgb.r, .rgb.g, .rgb.b] | join(",")}]'
## Filter by RegEx
cat 256-colors.json | jq '[.[] | select(.name|test("Olive")) | {colorId, name, hex: .hexString, hsl: [.hsl.h, .hsl.s, .hsl.l] | join(","), rgb: [.rgb.r, .rgb.g, .rgb.b] | join(",")}]'
cat 256-colors.json | jq '[.[] | select(.name|test("Olive")) | {colorId, name, hex: .hexString, hsl: [.hsl.h, .hsl.s, .hsl.l] | join(","), rgb: [.rgb.r, .rgb.g, .rgb.b] | join(",")}]'
[
{
"id": 3,
"color": "Olive",
"hex": "#808000",
"hsl": "60,100,25",
"rgb": "128,128,0"
},
...
]# OSX
python -m pip install --user virtualenv # osx
sudo pip install --upgrade virtualenv
pip install virtualenv
python -m venv venv
source venv/bin/activate
pip install --upgrade pip
sudo pip install -r requirements.txt
# check venv
pip -V
# activate venv
source venv/bin/activate
# Upgrade pip
pip install --upgrade pip
# deactivate venv
deactivate
# Check System aliases
alias
# List missing ### doctring trail
cat incl.sh | grep '# usage:' | grep -v '###'
# List UNITTEST Items
cat incl.sh | grep -n -A1 'ppwide' | grep -A1 'UNITTEST'
# List Functions
cat inc.aws.sh | grep '() ' | tr -d '(){' | awk '{print $2}'
# List Function Array
cat inc.aws.sh | grep '() ' | tr -d '(){' | awk '{print $2}' | tr '\n' ' 'See below & requirements.txt.
# env_info
Main : /Users/bamdad/.zshrc
Platform : x86_64, OSX, Darwin, Kernel Version 23.0.0
Machine : x86_64
Uptime : 9:17 up 4 days, 23:08, 2 users, load averages: 1.62 1.54 1.13
Shell : /bin/zsh
Bash : GNU bash, version 5.2.15(1)-release (x86_64-apple-darwin22.1.0)
Zsh : zsh 5.9 (x86_64-apple-darwin23.0)
Python : Python 3.11.2
pip : pip 23.2
AWS : aws-cli/1.29.3 Python/3.11.2 Darwin/23.0.0 botocore/1.31.3
Boto3 : 1.28.3
Botocore : 1.31.3