Jsonfilter (jsonpath) hang

ping @jow author

is -i meant to read from a file just as piping from stdin?

Running cat test.json | jsonfilter -e '@[*].id' - OK.
Running jsonfilter -e '@[*].id' -i test.json - hang.

Strace shows:

execve("/usr/bin/jsonfilter", ["jsonfilter", "-e", "@[*].id", "-i", "test.json"], 0x7fd2dda060 /* 15 vars */) = 0
set_tid_address(0x7fb8a78258)           = 3828
brk(NULL)                               = 0x2cabe000
brk(0x2cac0000)                         = 0x2cac0000
mmap(0x2cabe000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x2cabe000
openat(AT_FDCWD, "/etc/ld-musl-aarch64.path", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/libubox.so.20230523", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
fcntl(3, F_SETFD, FD_CLOEXEC)           = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=65617, ...}) = 0
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0\267\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 960) = 960
mmap(NULL, 135168, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x7fb89b5000
mmap(0x7fb89d4000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0xf000) = 0x7fb89d4000
close(3)                                = 0
openat(AT_FDCWD, "/lib/libjson-c.so.5", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/local/lib/libjson-c.so.5", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib/libjson-c.so.5", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
fcntl(3, F_SETFD, FD_CLOEXEC)           = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=65574, ...}) = 0
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0\267\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 960) = 960
mmap(NULL, 135168, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x7fb8994000
mmap(0x7fb89b3000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0xf000) = 0x7fb89b3000
close(3)                                = 0
openat(AT_FDCWD, "/lib/libgcc_s.so.1", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
fcntl(3, F_SETFD, FD_CLOEXEC)           = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=131088, ...}) = 0
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0\267\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 960) = 960
mmap(NULL, 200704, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x7fb8963000
mmap(0x7fb8992000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x1f000) = 0x7fb8992000
close(3)                                = 0
mprotect(0x7fb89d4000, 4096, PROT_READ) = 0
mprotect(0x7fb89b3000, 4096, PROT_READ) = 0
mprotect(0x7fb8992000, 4096, PROT_READ) = 0
mprotect(0x41f000, 4096, PROT_READ)     = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb8a70000
readv(0, 

So it's either stuck in parse_json or parse_json_chunk.

Probably the while loop doesn't iterate.

Reference test.json:

[
  {
    "id": 6683,
    "name": "example.org.",
    "type": "NS",
    "content": "b.ns.example.net.",
    "ttl": 86400,
    "zone_id": 3,
    "created_at": "2015-01-17T13:08:37.522452Z",
    "updated_at": "2015-01-17T13:08:37.522452Z"
  }
]

I believe the file spec (or raw json input) has to come before the expression parsing, try flipping the order so it's jsonfilter -i ... -e ....

Damn. I see it now. It'll hang if you supply the file parameter last, instead of before the -e parameter. :slightly_frowning_face:

I think it's waiting for stdin input for that first expression... Once that's satisfied, it probably moves on to reading test.json.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.