-1

I have a CURL on my sh script. I need save it`s ddecoded ata.

curl -H "Content-Type: application/json" -X POST -d '{"hash":"$restearterHash"}' {$host}ApiController/jsonRestarter/ | python -m json.tool

how to save data in the varible?

4
  • json.tool doesn't change the output into JSON -- if json.tool accepts it as input, it's already JSON to start with. Commented Sep 30, 2017 at 14:01
  • okay. Both options work. How then can i refer to a specific element of this json? Commented Sep 30, 2017 at 14:13
  • 1
    You'd use jq for that. We already have lots of questions and answers in the knowledgebase describing how to do so; please search before you ask. Commented Sep 30, 2017 at 14:14
  • I'm bad in English. Please help me find it. Commented Sep 30, 2017 at 14:18

2 Answers 2

0

You could use command substitution:

VAR=$(curl -H "Content-Type: application/json" -X POST -d '{"hash":"$restearterHash"}' {$host}ApiController/jsonRestarter/ | python -m json.tool)
echo "${VAR}"
Sign up to request clarification or add additional context in comments.

1 Comment

Welcome to StackOverflow, and thank you for using proper code formatting and providing a link to authoritative documentation! That said, note the section "Answer Well-Asked Questions" in How to Answer, particularly the following bullet point regarding questions which "have already been asked and answered many times before".
0

You can store the output of a command like this: var=`command`, so this should work fine for you: json=`curl -H "Content-Type: application/json" -X POST -d '{"hash":"$restearterHash"}' {$host}ApiController/jsonRestarter/ | python -m json.tool`

2 Comments

var=$(somecommand) is the modern syntax (present in the 1991 POSIX sh standard, so present in any standard-compliant shell written or updated in more than 25 years). $() nests better than backticks, and backslash literals contained therein have less surprising behavior.
Also, see How to Answer in the help center, particularly the section "Answer Well-Asked Questions", particularly the section requesting that one not answer questions that have been asked and answered many times before.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.