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

mnille
  • 1,328
  • 4
  • 16
  • 20
skumar
  • 41
  • 1
  • 1
  • 3

2 Answers2

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
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
OrangesV
  • 322
  • 1
  • 2
  • 9
  • Hi thanks for your response. I tried that option, our unix flavor is not supporting the jq command. Is there any other way? – skumar Sep 30 '16 at 00:01
3

You can try sed:

sed -n 's|.*"status":"\([^"]*\)".*|status=\1|p' response.json
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
hedleyyan
  • 437
  • 3
  • 15