Send json http message with bash

I would like to send some data to a web service that only accept json object. I will use curl to do HTTP POST, but I am wondering if there is a library for creating a json object in bash.

Another requirement is to avoid installing other packages (rpm / apt-get), but only other bash files as libraries.

+4
source share
3 answers

This is an example of a BigQuery API form.

curl -H "Authorization: GoogleLogin auth=<<YOUR_TOKEN>>" \ -X POST \ -H "Content-type: application/json" \ -d '{"params":{"q":"select count(*) from [bigquery/samples/shakespeare];"},"method":"bigquery.query"}' \ 'https://www.googleapis.com/rpc' 
+11
source

Checkout TickTick .

This is a true Bash JSON parser.

The builder should be in the work soon (but it’s easy to create your own, just using Bash foreach).

 #!/bin/bash . /path/to/ticktick.sh # File DATA=`cat data.json` # cURL #DATA=`curl http://foobar3000.com/echo/request.json` tickParse "$DATA" echo ``pathname`` echo ``headers["user-agent"]`` 
+1
source

I recommend Jshon. http://kmkeen.com/jshon/

It is designed to be used as much as possible inside the shell and replaces the fragile adhoc parsers created from grep / sed / awk, as well as the heavyweight single-line parsers from perl / python.

Jansson is required, but you can create a static version of the link.

0
source

Source: https://habr.com/ru/post/1369168/


All Articles