2

How can I read a JSON variable in shell script ( to be noted "JSON variable " and not JSON File)? I have tried something like,

temp={\"name\":\"Sipdy\",\"time\":\"17:09 1985\",\"place\":\"CA\"}
jq '.time' $temp

and also tried

temp={"name":"Sipdy","time":"17:09 1985","place":"CA"}
jq '.time' $temp

but both the above commands expect a JSON file name in place of "$temp".

1 Answer 1

1

You need to provide the JSON text as jq's standard input:

$ temp='{"name":"Sipdy","time":"17:09 1985","place":"CA"}'
$ echo $temp | jq .time                                   
"17:09 1985"
$ jq .time <<< $temp
"17:09 1985"

(The second form is a here string.)

Sign up to request clarification or add additional context in comments.

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.