简体   繁体   English

用shell脚本解析json

[英]parsing json with shell script

Wanted to parse json : 想要解析json

{"FileStatus":"accessTime":1472892839430,"blockSize":134217728,"childrenNum":0,"fileId":17226,"group":"admin","length":115714,"modificationTime":1469649837471,"owner":"admin","pathSuffix":"","permission":"755","replication":2,"storagePolicy":0,"type":"FILE"}}

I tried something like this but not able to get it. 我尝试了类似的方法,但无法获得。

$ {"FileStatus":{"accessTime":1472892839430}} | jq '.FileStatus.accessTime'

Error: 错误:

-bash: {FileStatus:{accessTime:1472892839430}}: command not found`

Can someone help me to parse this whole json . 有人可以帮我解析整个json

To make a command read a string on stdin in bash, use a "here string" like this: 要使命令在bash中的stdin上读取字符串,请使用“ here字符串”,如下所示:

$ jq '.FileStatus.accessTime' <<<'{"FileStatus":{"accessTime":1472892839430}}'
1472892839430

Also, you need to properly quote the text, so that bash doesn't try to interpret in some way you don't intend. 另外,您需要正确地引用文本,以便bash不会尝试以您不希望的某种方式进行解释。 When you want to preserve it literally, use single quotes ( ' ). 如果要按字面意义保留它,请使用单引号' )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM