Nested JSON not working as expected with HTTPie in Zsh

727 Views Asked by At

I can't figure out why sending nested JSON with HTTPie doesn't work as expected in Zsh. It looks like Zsh is trying to match bracket contents by default, but turning off matching (via noglob, nomatch, etc options) doesn't seem to work, and Httpie forms the literal foo[bar] instead of nesting the object:

> http --offline -v POST :/someurl foo[bar]=baz
zsh: no matches found: foo[bar]=baz

> noglob http --offline -v POST :/someurl foo[bar]=baz
POST /someurl HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 19
Content-Type: application/json
Host: localhost
User-Agent: HTTPie/2.6.0

{
    "foo[bar]": "baz"
}

I'm using Httpie 3.0.2, and the same operation works as expected in Bash. I.e.:

{
    "foo": {
        "bar": "baz"
    }
}
1

There are 1 best solutions below

4
Stephane Chazelas On

[...] is a globbing operator in most shells including zsh and needs to be quoted.

You'd have problems in other shells as well if there were some files in the current directory whose name matched that foo[bar]=baz glob pattern (try in bash/dash/ksh... after touch foob=bar fooa=bar for instance).

In bash and other POSIX shells, if no such file exist, the glob is passed literally by default, though the failglob and nullglob options can affect it.

Here, you need:

http --offline -v POST :/someurl 'foo[bar]=baz'