Giter Club home page Giter Club logo

Comments (3)

jkbrzt avatar jkbrzt commented on May 26, 2024

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

from cli.

XizumiK avatar XizumiK commented on May 26, 2024

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

from cli.

XizumiK avatar XizumiK commented on May 26, 2024

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.

from cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.