小编Dav*_*ers的帖子

获取匹配的不区分大小写字符串的键值

我正在尝试从“id”字段中提取一些特定数据,但jq匹配项区分大小写并造成搜索问题(基本上不匹配,因此返回 0 结果)。

JSON 示例:

{
  "created_at": "2020-01-17T12:54:02Z",
  "primary": true,
  "verified": true,
  "deliverable_state": "deliverable",
  "undeliverable_count": 0,
  "updated_at": "2020-01-17T12:54:03Z",
  "url": "http://www.website.com",
  "id": 376062709553,
  "user_id": 374002305374,
  "type": "email",
  "value": "test-1234567@domain.com"
}
{
  "created_at": "2019-02-07T20:49:41Z",
  "primary": false,
  "verified": true,
  "deliverable_state": "deliverable",
  "undeliverable_count": 0,
  "updated_at": "2019-02-07T20:49:41Z",
  "url": "http://www.website.com",
  "id": 366235941554,
  "user_id": 374002305374,
  "type": "email",
  "value": "MyEmail@domain.com"
}
Run Code Online (Sandbox Code Playgroud)

在jq针对以下情况运行时,我得到了正确的回报:

$ jq -r '. | select(.value=="MyEmail@domain.com") .id' sample.json
366235941554
Run Code Online (Sandbox Code Playgroud)

但是,如果我使用不正确的情况运行,例如。

$ jq -r '. | select(.value=="Myemail@domain.com") .id' sample.json
Run Code Online (Sandbox Code Playgroud)

......我没有得到结果。我已经阅读了一些文档,但不幸的是,我不明白用于不敏感搜索的测试/匹配/捕获标志(https://stedolan.github.io/jq/manual/#RegularexpressionsPCRE)或如何获取它使用此“定位并给我值”请求进行操作。

我似乎到处搜索,但找不到任何使用此方法的示例。

json jq

3
推荐指数
1
解决办法
1104
查看次数

标签 统计

jq ×1

json ×1