Stuck at sending an array of numbers using HTTPie

174 Views Asked by At

I want to send this JSON using HTTPie:

{
    name: 'John',
    phones: [
        1234,
        5678
    ]
}

And this is the parameters that I add to the httpie command:

name=John phones[]:=1234 phones[1]:5678

However, it does not compile (shows error).

If I remove those colons:

name=John phones[]=1234 phones[1]=5678

It works, but I get this JSON being sent as the body:

{
    "name": "John",
    "phones[][1]": "1234",
    "phones[][]": "5678"
}

How can I get that body? What parameters should I provide?

1

There are 1 best solutions below

0
0stone0 On BEST ANSWER

There's no need for the index, try:

name='John' \
phones[]=1234 \
phones[]= 5678 \

The := in your first try indicated 'Raw JSON fields', so if you'd like to use that, use:

phones:='[1234, 5678]'