What's the easiest way to do a JSON call from the command-line? I have a website that does a JSON call to retrieve additional data.
The Request Payload as shown in Google Chrome looks like this:
{"version": "1.1", "method":"progr","id":2,"params":{"call":...} }
It's about doing the call from (preferably) linux command line and retrieving the JSON content, not about parsing the incoming JSON data.
To answer your question, yes you may pass JSON in the URI as part of a GET request (provided you URL-encode).
To post JSON data using Curl, you need to set the Content-Type of your request to application/json and pass the JSON data with the -d command line parameter. The JSON content type is set using the -H "Content-Type: application/json" command line parameter. JSON data is passed as a string.
A request payload is data that clients send to the server in the body of an HTTP POST, PUT, or PATCH message that contains important information about the request.
You could use wget as well:
wget -O- --post-data='{"some data to post..."}' \ --header='Content-Type:application/json' \ 'http://www.example.com:9000/json'
Calling wget
with the option -O
providing the -
(space in between will be ignored, so it could also be written as -O -
) to it as its value will cause wget
to output the HTTP response directly to standard output instead into a file. The long option name for that is --output-document=file
.
Use curl, assuming the data is POST'ed, something like
curl -X POST http://example.com/some/path -d '{"version": "1.1", "method":"progr","id":2,"params":{"call":...} }'
If you're just retrieving the data with a GET , and don't need to send anything bar URL parameters, you'd just run curl http://example.com/some/path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With