Answer the question
In order to leave comments, you need to log in
Remove from jq keys containing part of a word?
There is a flat json how to use jq to remove from it all keys in the name of which there is the word pass
{
"description": "",
"hostname": "ubuntu18",
"ip": "",
"password_1": "test123",
" password_2": "test1231",
"username_1": "test",
"username_1_owner": "dude1",
"username_2": "test1",
"username_2_owner": "dude2"
}
Answer the question
In order to leave comments, you need to log in
$ jq 'with_entries(select(.key|test("password")|not))' config.json
{
"description": "",
"hostname": "ubuntu18",
"ip": "",
"username_1": "test",
"username_1_owner": "dude1",
"username_2": "test1",
"username_2_owner": "dude2"
}
Object.keys(obj).forEach(key => {
if (key.includes('pass')) {
delete obj[key];
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question