httpie / cli

🥧 HTTPie CLI — modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more.
https://httpie.io
BSD 3-Clause "New" or "Revised" License
32.67k stars 3.68k forks source link

Online doc error #1567

Closed XizumiK closed 3 months ago

XizumiK commented 3 months ago

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"]' 
jkbrzt commented 3 months ago

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

XizumiK commented 3 months ago

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

XizumiK commented 3 months ago

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.