开发者

Send json HTTP post with bash

I would like to send some data to a web service which accept only a json object. I will use curl to make the HTTP POST but I am wondering it there is a library to create a 开发者_如何学Cjson object in bash.

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


This is an example taken form BigQuery API

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'


Checkout TickTick.

It's a true Bash JSON parser.

A stringifier should be in the works shortly, (but it wouldn't be difficult to create your own just using bash's 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"]``


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

It is designed to be as usable as possible from within the shell and replaces fragile adhoc parsers made from grep/sed/awk as well as heavyweight one-line parsers made from perl/python.

Requires Jansson,But you can build a static link version.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜