I have a JSON file as the below:
[{
"macAddress": "ac:5f:3e:87:d7:1a",
"ip": "1.2.3.4"
},
{
"macAddress": "ac:5f:3e:87:d7:2a",
"ip": "1.2.3.4"
},
{
"macAddress": "ac:5f:3e:87:d7:3a",
"ip": "1.2.3.4"
}]
use jq
to hash the macAddress
field like so:
jq .[] | hash(.macAddress)
Can I define my own hash function and let jq
to run the hash during the parsing process?
My expected hash function can be simple as using native linux command md5sum
echo -n "my_salt""42:12:20:2e:2b:ca" | md5sum
d973ea7c353e78ba1724efbc8054dfdc -
So the output json will be
[{
"macAddress": "d973ea7c353e78ba1724efbc8054dfdc",
"ip": "1.2.3.4"
},
{
"macAddress": "d973ea7c353e78ba1724efbc8054d2er",
"ip": "1.2.3.4"
},
{
"macAddress": "d973ea7c353e78ba2324efbc8054d123",
"ip": "1.2.3.4"
}]