httpie/cli

Online doc error

Closed this issue · 3 comments

https://httpie.io/docs/cli/non-string-json-fields

hobbies:='["http", "pies"]' \ # Raw JSON — Array

In my test (PyPI ver.), it should be

hobbies='["http", "pies"]'

instead of

hobbies:='["http", "pies"]' 

The linked docs section talks about embedding raw JSON. The := notation achieves that. It embeds the JSON snippet as is, here resulting in a nested array:

$ http --offline pie.dev/post hobbies:='["http", "pies"]'
{
    "hobbies": [
        "http",
        "pies"
    ]
}

Here, however, we use =, which embeds the value as a string:

$ http --offline pie.dev/post hobbies='["http", "pies"]'
{
    "hobbies": "[\"http\", \"pies\"]"
}

Therefore, the docs is correct.

Please note there’s also explicit syntax for constructing nested JSON structures: https://httpie.io/docs/cli/nested-json

The linked docs section talks about embedding raw JSON. The := notation achieves that. It embeds the JSON snippet as is, here resulting in a nested array:

$ http --offline pie.dev/post hobbies:='["http", "pies"]'
{
    "hobbies": [
        "http",
        "pies"
    ]
}

Here, however, we use =, which embeds the value as a string:

$ http --offline pie.dev/post hobbies='["http", "pies"]'
{
    "hobbies": "[\"http\", \"pies\"]"
}

Therefore, the docs is correct.

Please note there’s also explicit syntax for constructing nested JSON structures: https://httpie.io/docs/cli/nested-json

Sorry, but when I run the command

http --offline pie.dev/post hobbies:='["http", "pie"]'

It gives me an error

error:
        'hobbies:=': Expecting value: line 1 column 2 (char 1)

Did I do something wrong? THX

The linked docs section talks about embedding raw JSON. The := notation achieves that. It embeds the JSON snippet as is, here resulting in a nested array:

$ http --offline pie.dev/post hobbies:='["http", "pies"]'
{
    "hobbies": [
        "http",
        "pies"
    ]
}

Here, however, we use =, which embeds the value as a string:

$ http --offline pie.dev/post hobbies='["http", "pies"]'
{
    "hobbies": "[\"http\", \"pies\"]"
}

Therefore, the docs is correct.
Please note there’s also explicit syntax for constructing nested JSON structures: https://httpie.io/docs/cli/nested-json

Sorry, but when I run the command

http --offline pie.dev/post hobbies:='["http", "pie"]'

It gives me an error

error:
        'hobbies:=': Expecting value: line 1 column 2 (char 1)

Did I do something wrong? THX

Update:
Try to run this code on my Debian VM, everything goes well

$ http --offline pie.dev/post hobbies:='["http", "pie"]'
POST /post HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 28
Content-Type: application/json
Host: pie.dev
User-Agent: HTTPie/3.2.1

{
    "hobbies": [
        "http",
        "pie"
    ]
}

So it's might be an issue just relate to the Windows Powershell.