jq删除匹配多个字符串中的一个的嵌套项



我正在尝试使用jq编辑作曲家。

这里我可以输入选择我想删除的项目,但我不知道如何把它变成delete声明。

另外-我可以让选择工作的唯一方法是使用to_entries,然后打破了要求选择的结构。

任何帮助将不胜感激!

作曲家。Json(为更短的帖子而修改):

{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"php": "^8.0",
"kreait/laravel-firebase": "^4.1",
"laravel/cashier-paddle": "^1.5",
"laravel/framework": "^8.75",
"laravel/sanctum": "^2.11",
"laravel/socialite": "^5.5",
"laravel/tinker": "^2.5",
"livewire/livewire": "^2.5",
"lorisleiva/laravel-actions": "^2.4",
"owenvoke/blade-fontawesome": "*",
"protonemedia/laravel-verify-new-email": "^1.5",
"pusher/pusher-php-server": "^7.0",
"rapidstatic/rapidstatic": "dev-master",
"rapidstatic/scraper": "dev-master",
"razorui/blade-application-ui": "^0.3.0"
}
}

金桥:

jq '.require | to_entries | map(select(.key | contains("rapidstatic")))' composer.json

输出:

[
{
"key": "rapidstatic/rapidstatic",
"value": "dev-master"
},
{
"key": "rapidstatic/scraper",
"value": "dev-master"
}
]

您可以使用del并提供如下键名:

jq '.require |= del(.[keys[] | select(contains("rapidstatic"))])' composer.json

演示或者您可以生成一个路径表达式数组并对它们使用delpaths:

jq '.require |= delpaths([keys[] | select(contains("rapidstatic")) | [.]])' composer.json

演示输出:

{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^8.0",
"kreait/laravel-firebase": "^4.1",
"laravel/cashier-paddle": "^1.5",
"laravel/framework": "^8.75",
"laravel/sanctum": "^2.11",
"laravel/socialite": "^5.5",
"laravel/tinker": "^2.5",
"livewire/livewire": "^2.5",
"lorisleiva/laravel-actions": "^2.4",
"owenvoke/blade-fontawesome": "*",
"protonemedia/laravel-verify-new-email": "^1.5",
"pusher/pusher-php-server": "^7.0",
"razorui/blade-application-ui": "^0.3.0"
}
}

相关内容

  • 没有找到相关文章

最新更新