0

I know how to store a string as a variable, for example: API="http://localhost:4741"

However, for the sake of a CURL request I would like to be able to store on object as a variable that I can access values on, something like OBJ="{name : Joe}". Is this possible?

Right now my CURL request looks like this:

curl --include --request POST localhost:3000/scrape \
  --header "Content-Type: application/json" \
  --data '{
    "url": "http://www.oddsshark.com/stats/gamelog/basketball/nba/20736",
    "team": "LA Clippers"
  }'

I would like to be able to do something like this, using a dictionary or an object:

TEAM=( ["Clippers"]="http://www.oddsshark.com/stats/gamelog/basketball/nba/20736" )
curl --include --request POST localhost:3000/scrape \
  --header "Content-Type: application/json" \
  --data '{
    "url": "http://www.oddsshark.com/stats/gamelog/basketball/nba/20736",
    "team": "${TEAM[Clippers]}"
  }'
Ben Melito
  • 131
  • 2
  • 12
  • 1
    Add output of your curl request to your question. – Cyrus Jun 22 '17 at 17:19
  • Would something like [this](https://stackoverflow.com/questions/1494178/how-to-define-hash-tables-in-bash) work? – 0x5453 Jun 22 '17 at 17:19
  • You can. And then use `jq` to parse the JSON. See [this](https://stackoverflow.com/questions/1955505/parsing-json-with-unix-tools) – Jedi Jun 22 '17 at 17:19
  • *Updated. I tried what you suggested @0x5453 to no avail, maybe I need to update my bash though – Ben Melito Jun 22 '17 at 17:43
  • So I'm actually using zsh rather than bash - will this prevent me from using the solution provided by @0x5453 ? – Ben Melito Jun 22 '17 at 18:09
  • @BenMelito Looks like the [syntax](http://hyperpolyglot.org/unix-shells#associative-arrays) is mostly the same. Note that if this is in a script, you can always set bash as the interpreter for the script, even if you are running from zsh: `#!/bin/bash` – 0x5453 Jun 22 '17 at 19:54
  • Awesome, thanks so much @0x5453 – Ben Melito Jun 22 '17 at 21:20

0 Answers0