jq 未在 Cygwin 中处理 JSON 文件

jq not processing a JSON file in Cygwin

当我尝试在 cygwin 中使用 jq 处理 json 文件时,我总是收到消息

assertion "cb == jq_util_input_next_input_cb" failed: file "/usr/src/ports/jq/jq-1.6-1.x86_64/src/jq-1.6/src/util.c", line 371, function: jq_util_input_get_position

我看过一些关于此的其他帖子,但我似乎没有找到解决方案。有什么办法让它工作吗?

我在 cygwin 中使用 jq 1.6。

更新:

这是我的 JSON 文件:

{
  "users": [
    {
      "userId": 1,
      "firstName": "firstName_1",
      "lastName": "lastName_1",
      "phoneNumber": "111111111",
      "emailAddress": "emailAddress_1@email.com"
    },
    {
      "userId": 2,
      "firstName": "firstName_2",
      "lastName": "lastName_2",
      "phoneNumber": "222222222",
      "emailAddress": "emailAddress_2@email.com"
    },
    {
      "userId": 3,
      "firstName": "firstName_3",
      "lastName": "lastName_3",
      "phoneNumber": "333333333",
      "emailAddress": "emailAddress_3@email.com"
    },
    {
      "userId": 4,
      "firstName": "firstName_4",
      "lastName": "lastName_4",
      "phoneNumber": "444444444",
      "emailAddress": "emailAddress_4@email.com"
    },
    {
      "userId": 5,
      "firstName": "firstName_5",
      "lastName": "lastName_5",
      "phoneNumber": "555555555",
      "emailAddress": "emailAddress_5@email.com"
    }
  ]
}

如果我使用这个:

echo "$(<file_1.json)" | jq -r '["ID","NAME"], ["--","------"], (.users[] | .userId, .lastName)'

我明白了:

[
  "ID",
  "NAME"
]
[
  "--",
  "------"
]
1
lastName_1
2
lastName_2
3
lastName_3
4
lastName_4
5
lastName_5

如果我试试这个:

echo "$(<file_1.json)" | jq -r '["ID","NAME"], ["--","------"], (.users[] | .userId, .lastName) | @tsv'

我明白了:

ID      NAME
--      ------
assertion "cb == jq_util_input_next_input_cb" failed: file "/usr/src/ports/jq/jq-1.6-1.x86_64/src/jq-1.6/src/util.c", line 371, function: jq_util_input_get_position
                    Aborted (core dumped)

我是基于这个link:

您缺少 .userId, .lastName 周围的数组括号(它们也存在于您链接到的解决方案中)。

["ID","NAME"], ["--","------"], (.users[] | [.userId, .lastName]) | @tsv
ID  NAME
--  ------
1   lastName_1
2   lastName_2
3   lastName_3
4   lastName_4
5   lastName_5

Demo