Comments (23)
I would prefer javascript compatible syntax, so http post parent.child=value
and the more complex syntax for embedded dots: [parent.with.dots]=value
. The common use case should be easiest and json properties with dots are ugly to use in javascript.
from httpie.
For deeply nested JSON it's easier to use stdin
. For example:
echo '{"foo": {"bar": "baz"}}' | http url
# Or from a file:
http url < file.json
More examples are listed in the README.
from httpie.
httpie is a dream! nesting would make it even more awesome though.
It would be nice with rails-like nesting, e.g. path/to/endpoint credentials[username]=me
from httpie.
@jakubroztocil This issue has been open for 6 years! And it is such a rudimentary feature! Of course, we can all do echo
, but we can use curl
as well, right? The point is that httpie
does all the basic REST operations. Of course, we can use it along with jarg or jo, but it's so easy to implement this within httpie
, I think!
from httpie.
@jkbrzt For clarification are you referencing jarg for your own notes/feature development? I tried the following which didn't work:
http post localhost:3000/api foo[bar]=baz
Is received as:
body= { 'foo[bar]': 'baz' }
However, piping through jarg does seem to work:
jarg foo[bar]=baz | http post localhost:3000/api
Is received as:
body= { foo: { bar: 'baz' } }
from httpie.
I donโt think itโs that simple, or someone would have sent a pull request!
We should appreciate projects written on free time and given for free.
from httpie.
๐ This feature is now publicly available in HTTPie for Terminal 3.0:
๐๐ป https://httpie.io/docs/cli/nested-json
from httpie.
Syntax: https://www.w3.org/TR/html-json-forms/
from httpie.
Answering my own question:
http -v PUT http://10.10.10.219:8080/v2/apps/product/web/tutum-hello-world-1 instances:=2 constraints:='[["hostname", "LIKE", server1.localnet.nett"]]'
PUT /v2/apps/product/web/tutum-hello-world-1 HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Content-Length: 85
Content-Type: application/json; charset=utf-8
Host: 10.9.158.219:8080
User-Agent: HTTPie/0.8.0
{
"constraints": [
[
"hostname",
"LIKE",
"server1.localnet.net"
]
],
"instances": 2
}
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, must-revalidate
Content-Length: 92
Content-Type: application/json
Expires: 0
Pragma: no-cache
Server: Jetty(8.y.z-SNAPSHOT)
{
"deploymentId": "bde62f56-89f6-406a-9c3a-d0309ea3dde6",
"version": "2015-06-10T12:28:06.056Z"
}
Thanks!!
Alex
from httpie.
@merwork We appreciate it. But how many REST services you know to have only a flat JSON?
from httpie.
If you don't like piping JSON from jo
or jarg
before the http command. you can also use shell process substitution so the JSON is in a similar location when using the builtin syntax of HTTPie:
https postman-echo.com/post @<(jo hello=world)
It would still be much better if HTTPie supported a syntax like those tools of course.
from httpie.
An important consideration here is backwards compatibility. If we simply introduce a syntax relying on dots, than a script containing the following HTTPie command:
$ http httpbin.org/post foo.bar=baz
Which currently produces this JSON:
{
"foo.bar": "baz"
}
Would unexpectly result in:
{
"foo": {
"bar": "baz"
}
}
So the command would have to be updated to escape the newly-meanignful .
character:
$ http httpbin.org/post 'foo\.bar=baz'
from httpie.
Some sort of easier syntax for nested data would really be a nice thing to have.
There is also another issue with some syntax suggestions: #346
from httpie.
So nesting could be expressed either with brackets or using dot notation.
from httpie.
Greetings!!! Small question regarding nested json and httpie. So I have a json file:
{
"apps": [
{ "id": "/product/web/tutum-hello-world-2",
"container": {
"type": "DOCKER",
"docker": {
"image": "tutum/hello-world",
"network": "BRIDGE"
}
},
"id": "/product/web/tutum-hello-world-2",
"instances": 1,
"cpus": 0.25,
"mem": 256,
"uris": [],
"constraints": [["hostname", "LIKE", "server1.localnet.net"]]
}
]
}
I want to increase the value of "instances":
to 2
and use "constraints": [["hostname", "LIKE", "server1.localnet.net"]]
. I tried different permutations, but I am getting No JSON object could be decoded
over and over again :(
Using just instances:
is pretty easy:
root@node108:~# http -v PUT http://10.10.10.219:8080/v2/apps/product/web/tutum-hello-world-1 instances:=1
PUT /v2/apps/product/web/tutum-hello-world-1 HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Content-Length: 16
Content-Type: application/json; charset=utf-8
Host: 10.9.158.219:8080
User-Agent: HTTPie/0.8.0
{
"instances": 1
}
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, must-revalidate
Content-Length: 92
Content-Type: application/json
Expires: 0
Pragma: no-cache
Server: Jetty(8.y.z-SNAPSHOT)
{
"deploymentId": "6eeda6ac-2ec1-4554-95f3-a0dc19333c56",
"version": "2015-06-10T11:33:53.165Z"
}
...however using it TOGETHER with constraints
directive + nested values has proven to be difficult (for me). Any help, please ???
Thanks!!!!
from httpie.
@lastcoolnameleft yes, I was just bookmarking that spec. Sorry for the confusion.
from httpie.
Hi, I am not sure to understand, how do you provided nested json object with Httpie
from httpie.
any updates on this issue?
I'd also prefer what @akvadrako suggested
from httpie.
agree that this would be very welcome.
from httpie.
Many that I write :)
Thanks for the pointers to jarg and jo! Goes well in my json toolbox with jq and gron.
from httpie.
+1 for the compat issue, but the proposed solution should be more complicated:
$ http httpbin.org/post "foo\.bar=baz"
otherwise the shell escape \.
is interpreted by the shell as .
and the backslash is not passed to the command called.
from httpie.
@merwok Good point. Iโve updated the example to take shell escaping into account. General request item escaping rules apply.
from httpie.
Note that since HTTPie 2.5.0, you can use --raw
in the same way you do curl -d
:
$ http pie.dev/post --raw '{"foo": {"bar": "baz"}}'
{
"foo": {
"bar": "baz"
}
}
from httpie.
Related Issues (20)
- More statuses support HOT 1
- Unable to install httpie via Chocolatey HOT 14
- [macOS] Lag when piping stdout HOT 5
- Display a warning for using option --ignore-stdin when request fails with content present in stdin
- Request is fired to packages.httpie.io on every invocation of `http` HOT 1
- How to post an empty string as a data field? HOT 2
- werkzeug compatibility
- Docs: Ubuntu/Debian installation script gives error
- Does not work with a small easy peasy sample 'http -f requests.http' HOT 4
- Add shortcut to --verify=no
- Default headers by domain
- Add support for OAuth2 authentication
- Can't install a plugin because cannot invoke pip
- HTTPS_PROXY not working
- Hash character `#` in a query string causes the rest of the string to be ignored HOT 2
- Trim trailing empty lines from CLI output HOT 1
- Cryptographic API Misuse Vulnerability : Missing SSL Certificate Validation HOT 1
- Filter response keys before print result to the screen
- HTTPie could be lead to believe data was passed in stdin when it was not HOT 1
- httpie -d does not work with gzip compressed content
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from httpie.