Home > Software engineering >  jq not processing a JSON file in Cygwin
jq not processing a JSON file in Cygwin

Time:03-30

When I try to use jq in cygwin to process a json file, I always get the message

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

I've seen some other posts on this but I don't seem to find the solution. Is there any way to get it to work?

I'm using jq 1.6 in cygwin.

Update:

This is my JSON file:

{
  "users": [
    {
      "userId": 1,
      "firstName": "firstName_1",
      "lastName": "lastName_1",
      "phoneNumber": "111111111",
      "emailAddress": "[email protected]"
    },
    {
      "userId": 2,
      "firstName": "firstName_2",
      "lastName": "lastName_2",
      "phoneNumber": "222222222",
      "emailAddress": "[email protected]"
    },
    {
      "userId": 3,
      "firstName": "firstName_3",
      "lastName": "lastName_3",
      "phoneNumber": "333333333",
      "emailAddress": "[email protected]"
    },
    {
      "userId": 4,
      "firstName": "firstName_4",
      "lastName": "lastName_4",
      "phoneNumber": "444444444",
      "emailAddress": "[email protected]"
    },
    {
      "userId": 5,
      "firstName": "firstName_5",
      "lastName": "lastName_5",
      "phoneNumber": "555555555",
      "emailAddress": "[email protected]"
    }
  ]
}

If I use this:

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

I get this:

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

If I try this:

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

I get this:

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)

I was basing on this link: How to format a JSON string as a table using jq?

CodePudding user response:

You were missing the array brackets around .userId, .lastName (which are also present in the solution you have linked to).

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

Demo

  • Related