Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to grep the specific field value from json string using shell script [duplicate]

Tags:

json

bash

shell

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

like image 940
skumar Avatar asked Mar 11 '23 00:03

skumar


1 Answers

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
like image 95
OrangesV Avatar answered Apr 27 '23 20:04

OrangesV