-d '{ "foo": "bar", "zed": "yow" }'
The proposed --jp flag seems worse to me in every way.
(Note I do like the --json as just syntactic sugar for -H "Accept: application/json" -d <jsonBody>)
-d '{ "foo": "bar", "zed": "yow" }'
The proposed --jp flag seems worse to me in every way.
(Note I do like the --json as just syntactic sugar for -H "Accept: application/json" -d <jsonBody>)
bash$ curl ... --jp "foo=$foo" ...
This has zero shell-quoting, expansion, escaping, or separator issues. Whatever's in environment variable `foo` will be sent to the server as a single value associated with key `foo`, whether it's a zero-length empty string, or full of backslashes or spaces or newlines or whatever.There are fancier ways to accept multi-arg, but they all have weaknesses, and this matches the way curl handles -H arguments already today (one per header, stack them if you want many), so I think it's a sound way to handle CLI arguments.
(I don't have any specific views on whether this is how curl should do JSON or not, but I recognized the CLI safety mechanism immediately.)
Yeah, actually it is. It's immediately intuitive to me. It makes string interpolation way easier. Quick, how do you do -d {object} and pass in environment variables with correct string escaping? Do you start with single quote or double quote? Where do I put backslashes? Bash vs zsh compatibility? Plus you have to make sure all the slashes, quotes, brackets and braces match.
Vs
--jp foo=$FOO --jp bar="baz-${BAR:-default-bar}" --jp date="\"$(date)\""
(I'm iffy on the last one, but it's WAY easier than trying to build that into an object)
If it's going to properly crib `jo` syntax, you can just do `date="$(date)"` - no need for the second set of quotes (and, indeed, they'll mess it up.)
> jo date="$(date)"
{"date":"Thu 20 Jan 2022 20:59:16 GMT"}
> jo date="\"$(date)\""
{"date":"\"Thu 20 Jan 2022 21:00:28 GMT\""}It is so weird that command-f on that wiki doesn't show a single content-type header
The notation seems to be similar to HAML<>HTML. It's not JSON, and it doesn't make any sense other than really short ad hoc queries. It's just confusing and only solves a problem that a tiiiny amount of people have (regualar ad hoc json queries, where people are too lazy to actually write out json).
Otherwise, why not do the same for XML, css. Or heck.. why not simply support HAML as well
It's better to have such functionality extracted in some other tool and just pipe it
$ jp foo=bar zed=yow
{ "foo": "bar", "zed": "yow" }
$ jp foo=bar zed=yow | curl --json - https://example.com/destination
...result here... $ jo query="six times nine" answer=42 | curl --json -
Sending JSON...
{"query":"six times nine","answer":42}