6

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 json object in bash.

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

1
  • The place to look is json.org Commented Aug 26, 2011 at 14:17

3 Answers 3

13

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'
Sign up to request clarification or add additional context in comments.

Comments

2

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"]``

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.