Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jq is hanging when trying to extract data from json #1682

Closed
sudhakarcs50 opened this issue Jul 5, 2018 · 7 comments
Closed

jq is hanging when trying to extract data from json #1682

sudhakarcs50 opened this issue Jul 5, 2018 · 7 comments

Comments

@sudhakarcs50
Copy link

sudhakarcs50 commented Jul 5, 2018

Hi,

My Json file has following structure

{
"group0": [
    {
        "id": 9,
        "href": "href1",
        "name": "Americas",
        "group1": [
            {
                "id": 8,
                "href": "href2",
                "name": "Anguilla (UK)",
                "type": "country",
                "field0": "ai",
                "group2": {
                    "field1": 9,
                    "field2": 1,
                    "field3": 1
                }
            },
            {
                "id": 9,
                "href": "href3",
                "name": "Antigua and Barbuda",
                "type": "country",
                "field0": "ag",
                "group2": {
                    "field1": 9,
                    "field2": 1,
                    "field3": 2
                }
            },
            {
                "id": 10,
                "href": "href4",
                "name": "Argentina",
                "type": "country",
                "field0": "ar",
                "group2": {
                    "field1": 8,
                    "field2": 1,
                    "field3": 2
                },
                "group3": [
                    {
                        "id": 599,
                        "href": "",
                        "name": "Rosario and Santa Fe (both Santa Fe province)",
                        "field3": 3
                    }
                ]
            }
            
        ]
    },
    {
        "id": 10,
        "href": "href5",
        "name": "Asia & the Pacific",
        "group1": [
            {
                "id": 1,
                "href": "href6",
                "name": "Afghanistan",
                "type": "country",
                "field0": "af",
                "group2": {
                    "field1": 10,
                    "field2": 3,
                    "field3": 5
                }
            },
            {
                "id": 14,
                "href": "href7",
                "name": "Australia",
                "type": "country",
                "field0": "au",
                "group2": {
                    "field1": 7,
                    "field2": 1,
                    "field3": 2
                }
            },
            {
                "id": 19,
                "href": "href8",
                "name": "Bangladesh",
                "type": "country",
                "field0": "bd",
                "group2": {
                    "field1": 9,
                    "field2": 2,
                    "field3": 3
                },
                "group3": [
                    {
                        "id": 216,
                        "href": "",
                        "name": "Chittagong Hill Tracts; Dhaka",
                        "field3": 4
                    }
                ]
            }
            
        ]
    }  
]

}

i want to extract the fileds group1.field0, group1.name,group2.field1, group1.field3

the command i am running is below

jq '.group0[].group1[]|"\(.name)|\(.field0)|\(.group2.field1)|\(.group2.field3)"' sample.json

when i run the above command in Solaris it just hangs and does nothing. when i run the above command with only 2 fields i am getting data

jq '.group0[].group1[]|"\(.name)|\(.field0)"' sample.json

can someone please help me what am i doing wrong. the first command is working on jqplay.org which uses jq version 1.5 and jq version on our server is 1.4. i don't know whether lower version may be the issue(latest version for Solaris is 1.4 only).

@pkoppstein
Copy link
Contributor

pkoppstein commented Jul 5, 2018

Using jq 1.5:

jq '.group0[].group1[]|"\(.name)|\(.field0)|\(.group2.field1)|\(.group2.field3)"' sample.json
"Anguilla (UK)|ai|9|1"
"Antigua and Barbuda|ag|9|2"
"Argentina|ar|8|2"
"Afghanistan|af|10|5"
"Australia|au|7|2"
"Bangladesh|bd|9|3"

Same thing with jq 1.4 on MacOS.

Note carefully the occurrences of "\("

For future reference, please ask usage questions at stackoverflow.com with the jq tag:
https://stackoverflow.com/questions/tagged/jq

@sudhakarcs50
Copy link
Author

@pkoppstein

actually i was using that syntax only. it is working in jq 1.5(i was using jq 1.5 on jqplay.org) but not in jq 1.4 on solaris.

@sudhakarcs50
Copy link
Author

the same commands are working on jq 1.4 and 1.5 for Windows. i don't know whether this is issue with Solaris jq 1.4

@sudhakarcs50
Copy link
Author

@pkoppstein

it seems there is some bug in Jq 1.4 for Solaris as this command is working on Windows, Linux, OSX. below is the out put of the truss which is equivalent of strace. can you please check

/local> truss jq '.' ./DEMO.Json
execve("
/jq", 0xFFBFF4A4, 0xFFBFF4B4) argc = 3
sysinfo(SI_MACHINE, "sun4u", 257) = 6
mmap(0x00000000, 32, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON, -1, 0) = 0xFF1F0000
mmap(0x00000000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0) = 0xFF1A0000
mmap(0x00000000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0) = 0xFF190000
mmap(0x00000000, 8192, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON, -1, 0) = 0xFF180000
memcntl(0xFF1B0000, 18176, MC_ADVISE, MADV_WILLNEED, 0, 0) = 0
memcntl(0x00010000, 13976, MC_ADVISE, MADV_WILLNEED, 0, 0) = 0
resolvepath("/usr/lib/ld.so.1", "/lib/ld.so.1", 1023) = 12
resolvepath("/jq", "/jq", 1023) = 15
stat64("/jq", 0xFFBFEF68) = 0
open("/var/ld/ld.config", O_RDONLY) Err#2 ENOENT
stat64("/u01/app/oracle/product/11.2.0/db_1/lib/libc.so.1", 0xFFBFE6C8) Err#2 ENOENT
stat64("
/powercenter961q/server/bin/libc.so.1", 0xFFBFE6C8) Err#2 ENOENT
stat64("/powerexchange8q/libc.so.1", 0xFFBFE6C8) Err#2 ENOENT
stat64("
/java1.3/lib/libc.so.1", 0xFFBFE6C8) Err#2 ENOENT
stat64("/java1.3/jre/lib/libc.so.1", 0xFFBFE6C8) Err#2 ENOENT
stat64("
/sybase/OCS-15_0/lib/libc.so.1", 0xFFBFE6C8) Err#2 ENOENT
stat64("/usr/lib/libc.so.1", 0xFFBFE6C8) = 0
resolvepath("/usr/lib/libc.so.1", "/lib/libc.so.1", 1023) = 14
open("/usr/lib/libc.so.1", O_RDONLY) = 3
mmap(0x00010000, 32768, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_ALIGN, 3, 0) = 0xFF170000
mmap(0x00010000, 1368064, PROT_NONE, MAP_PRIVATE|MAP_NORESERVE|MAP_ANON|MAP_ALIGN, -1, 0) = 0xFF000000
mmap(0xFF000000, 1247557, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_TEXT, 3, 0) = 0xFF000000
mmap(0xFF142000, 35997, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_INITDATA, 3, 1253376) = 0xFF142000
mmap(0xFF14C000, 1640, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_ANON, -1, 0) = 0xFF14C000
munmap(0xFF132000, 65536) = 0
munmap(0xFF170000, 32768) = 0
close(3) = 0
mmap(0x00000000, 16384, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON, -1, 0) = 0xFF170000
memcntl(0xFF000000, 146196, MC_ADVISE, MADV_WILLNEED, 0, 0) = 0
mmap(0x00010000, 24576, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON|MAP_ALIGN, -1, 0) = 0xFF160000
getcontext(0xFFBFEDD8)
getrlimit(RLIMIT_STACK, 0xFFBFEDB8) = 0
getpid() = 2790 [2789]
setustack(0xFF162AC8)
brk(0x00059D98) = 0
brk(0x0005BD98) = 0
stat64("/platform/SUNW,SPARC-Enterprise/lib/libc_psr.so.1", 0xFFBFD3F8) = 0
resolvepath("/platform/SUNW,SPARC-Enterprise/lib/libc_psr.so.1", "/platform/sun4u-opl/lib/libc_psr.so.1", 1023) = 37
open("/platform/SUNW,SPARC-Enterprise/lib/libc_psr.so.1", O_RDONLY) = 3
mmap(0x00010000, 6580, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_ALIGN, 3, 0) = 0xFF150000
close(3) = 0
open("~/.jq", O_RDONLY) Err#2 ENOENT
brk(0x0005BD98) = 0
brk(0x0005DD98) = 0
brk(0x0005DD98) = 0
brk(0x0005FD98) = 0
open("./DEMO.Json.20180705-084421", O_RDONLY) = 3
fstat64(3, 0xFFBFE150) = 0
brk(0x0005FD98) = 0
brk(0x0006BD98) = 0
fstat64(3, 0xFFBFDFF8) = 0
ioctl(3, TCGETA, 0xFFBFE0DC) Err#25 ENOTTY
read(3, " { " r e g i o n s " : [".., 52224) = 51889
brk(0x0006BD98) = 0
brk(0x0006DD98) = 0
brk(0x0006DD98) = 0
brk(0x0006FD98) = 0
brk(0x0006FD98) = 0
brk(0x00071D98) = 0
brk(0x00071D98) = 0
brk(0x00073D98) = 0
brk(0x00073D98) = 0
brk(0x00075D98) = 0
brk(0x00075D98) = 0
brk(0x00077D98) = 0
brk(0x00077D98) = 0
brk(0x00079D98) = 0
brk(0x00079D98) = 0
brk(0x0007BD98) = 0
brk(0x0007BD98) = 0
brk(0x0007DD98) = 0
brk(0x0007DD98) = 0
brk(0x0007FD98) = 0
brk(0x0007FD98) = 0
brk(0x00081D98) = 0
brk(0x00081D98) = 0
brk(0x00083D98) = 0
brk(0x00083D98) = 0
brk(0x00085D98) = 0
brk(0x00085D98) = 0
brk(0x00087D98) = 0
brk(0x00087D98) = 0
brk(0x00089D98) = 0
brk(0x00089D98) = 0
brk(0x0008BD98) = 0
brk(0x0008BD98) = 0
brk(0x0008DD98) = 0
brk(0x0008DD98) = 0
brk(0x0008FD98) = 0
brk(0x0008FD98) = 0
brk(0x00091D98) = 0
brk(0x00091D98) = 0
brk(0x00093D98) = 0
brk(0x00093D98) = 0
brk(0x00095D98) = 0
brk(0x00095D98) = 0
brk(0x00097D98) = 0
brk(0x00097D98) = 0
brk(0x00099D98) = 0
brk(0x00099D98) = 0
brk(0x0009BD98) = 0
brk(0x0009BD98) = 0
brk(0x0009DD98) = 0
brk(0x0009DD98) = 0
brk(0x0009FD98) = 0
brk(0x0009FD98) = 0
brk(0x000A1D98) = 0
brk(0x000A1D98) = 0
brk(0x000A3D98) = 0
brk(0x000A3D98) = 0
brk(0x000A5D98) = 0
brk(0x000A5D98) = 0
brk(0x000A7D98) = 0
brk(0x000A7D98) = 0
brk(0x000A9D98) = 0
brk(0x000A9D98) = 0
brk(0x000ABD98) = 0
brk(0x000ABD98) = 0
brk(0x000ADD98) = 0
brk(0x000ADD98) = 0
brk(0x000AFD98) = 0
brk(0x000AFD98) = 0
brk(0x000B1D98) = 0
brk(0x000B1D98) = 0
brk(0x000B3D98) = 0
brk(0x000B3D98) = 0
brk(0x000B5D98) = 0
brk(0x000B5D98) = 0
brk(0x000B7D98) = 0
brk(0x000B7D98) = 0
brk(0x000B9D98) = 0
brk(0x000B9D98) = 0
brk(0x000BBD98) = 0
brk(0x000BBD98) = 0
brk(0x000BDD98) = 0
brk(0x000BDD98) = 0
brk(0x000BFD98) = 0
brk(0x000BFD98) = 0
brk(0x000C1D98) = 0
brk(0x000C1D98) = 0
brk(0x000C3D98) = 0
read(3, 0x0005E914, 52224) = 0
brk(0x000C3D98) = 0
brk(0x000C5D98) = 0
brk(0x000C5D98) = 0
brk(0x000C7D98) = 0
brk(0x000C7D98) = 0
brk(0x000C9D98) = 0
ioctl(1, TCGETA, 0xFFBFE194) = 0
ioctl(1, TCGETA, 0xFFBFDD04) = 0
fstat64(1, 0xFFBFDC20) = 0
{
write(1, "1B [ 3 7 m {\n", 7) = 7
"group0": [
write(1, " 1B [ 0 m1B [ 3 4 ; 1".., 44) = 44
{
write(1, " 1B [ 3 7 m {\n", 11) = 11
brk(0x000C9D98) = 0
brk(0x000CBD98) = 0
brk(0x000CBD98) = 0
brk(0x000CDD98) = 0
brk(0x000CDD98) = 0
brk(0x000CFD98) = 0
brk(0x000CFD98) = 0
brk(0x000D1D98) = 0
brk(0x000D1D98) = 0
brk(0x000D5D98) = 0
brk(0x000D5D98) = 0
brk(0x000D9D98) = 0
brk(0x000D9D98) = 0
brk(0x000E1D98) = 0
brk(0x000E1D98) = 0
brk(0x000E9D98) = 0
brk(0x000E9D98) = 0
brk(0x000F9D98) = 0
brk(0x000F9D98) = 0
brk(0x00109D98) = 0
brk(0x00109D98) = 0
brk(0x00129D98) = 0
brk(0x00129D98) = 0
brk(0x00169D98) = 0
brk(0x00169D98) = 0
brk(0x001E9D98) = 0
brk(0x001E9D98) = 0
brk(0x002E9D98) = 0
^C Received signal #2, SIGINT [default]

@pkoppstein
Copy link
Contributor

@sudhakarcs50 - I'm afraid I won't be able to help other than to suggest that you try to upgrade your version of jq on Solaris. jq 1.4 is very old.

Installing the "master" version of jq would probably be no more difficult than installing jq 1.5 so if I were in your shoes, I'd start with the "master" version.

@sudhakarcs50
Copy link
Author

@pkoppstein, it seems JQ 1.5 for Solaris was not released and our admin team had issues with compiling from the source tar ball

@pkoppstein
Copy link
Contributor

@sudhakarcs50 - One does not need admin permissions to install jq.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants