如何使用shell脚本从json字符串grep指定的字段值 [英] How to grep the specific field value from json string using shell script
本文介绍了如何使用shell脚本从json字符串grep指定的字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是文件中可用的JSON字符串,我需要在其中提取外壳脚本中 status
的值.
Below is my JSON string available in file, out of which I need to extract the value for status
in shell script.
预期输出: status = success
response.json
{"eventDate":null,"dateProccessed":null,"fileName":null,"status":"success"}
如果您需要任何信息,请告诉我
Please let me know, if you need any information
推荐答案
查看 jq
.这是一个非常方便的json解析器.
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
这篇关于如何使用shell脚本从json字符串grep指定的字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文