4

Below is my JSON string available in file, out of which I need to extract the value for status in shell script.

Expected Output: status=success

response.json

{"eventDate":null,"dateProccessed":null,"fileName":null,"status":"success"}

Please let me know, if you need any information

0

2 Answers 2

4

Look into jq. It is a very handy json parser.

If you want to extract just the status you can do something like:

jq -r '.status' response.json

# output
success

You can format your output as well to follow the results you want.

jq -r '"status=\(.status)"' response.json

# output
status=success
Sign up to request clarification or add additional context in comments.

1 Comment

Hi thanks for your response. I tried that option, our unix flavor is not supporting the jq command. Is there any other way?
3

You can try sed:

sed -n 's|.*"status":"\([^"]*\)".*|status=\1|p' response.json

3 Comments

How does this produce the expected output status=success?
@hek2mgl \1 will capture success. It's not a brilliant solution, but it will work.
I was overlooking that the input json is a one line document. sed is not brilliant here but you are right, it will work in this case.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.