Showing posts with label json. Show all posts
Showing posts with label json. Show all posts

Wednesday, October 23, 2013

How to post json with curl

i needed to test a php script by posting a json body in the request with curl from the debian linux command line. below is the solution i found.

curl -X POST -H "Content-Type: application/json" -d '{"key": "value"}' http://localhost/myscript.php


info taken from:
http://stackoverflow.com/questions/7172784/how-to-post-json-data-with-curl-from-terminal-commandline-to-test-spring-rest

Friday, October 18, 2013

bash regex to get json value

i needed a bash regex to get the value for a given key in a json file. below is my solution.

json.sh

getJsonValue()
{
    grep -Po '"'"$2"'"\s*:\s*"\K([^"]*)' $1
}

# example usage
# getJsonValue "json_file" "json_key"