Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在shell脚本中使用jq过滤器从stringify对象获取json对象_Json_Linux_Shell_Jq - Fatal编程技术网

在shell脚本中使用jq过滤器从stringify对象获取json对象

在shell脚本中使用jq过滤器从stringify对象获取json对象,json,linux,shell,jq,Json,Linux,Shell,Jq,我是新手,正在编写shell脚本。我的问题是 我有一个类似json的对象 { "logo": {"name":"logo.png","type":"image\/jpeg","tmp_name":"C:\\xampp\\tmp\\php8B97.tmp","error":0,"size":110290}, "template":"template1", "firstname":"a", "lastname":"a", "username":"a", "pass

我是新手,正在编写shell脚本。我的问题是 我有一个类似json的对象

{
   "logo": {"name":"logo.png","type":"image\/jpeg","tmp_name":"C:\\xampp\\tmp\\php8B97.tmp","error":0,"size":110290},
   "template":"template1",
   "firstname":"a",
   "lastname":"a",
   "username":"a",
   "password":"aa",
   "email":"a",
   "categoriesListArr":"{\"Women\":[\"All footwear\",\"All footwear\",\"All Clothing\",\"All Clothing\",\"All Watches\",\"All Watches\",\"All Sunglasses\",\"All Sunglasses\"],\"Men\":[\"All Mens Accessories\",\"All Bags,Belts And wallets\",\"All Fragrances\",\"All Grooming and wellness\"]}",
   "aboutUs":"aa",
   "contactUs":"78787878878787",
   "deliveryInfo":"aa",
   "privacyPolicy":"aa",
   "t&d":"aa"
}
我使用jq过滤器提取了categoriesListArr,如下所示:

categories=`cat detail.json| jq '.categoriesListArr'`
detail.json是文件名。 现在categories是stringify对象…我需要解析它并将其转换为json对象

"{\"Women\":[\"All footwear\",\"All footwear\",\"All Clothing\",\"All Clothing\",\"All Watches\",\"All Watches\",\"All Sunglasses\",\"All Sunglasses\"],\"Men\":[\"All Mens Accessories\",\"All Bags,Belts And wallets\",\"All Fragrances\",\"All Grooming and wellness\"]}"
如何使用jq过滤器将其转换为JSON格式是您的朋友:

$ jq '.categoriesListArr | fromjson' detail.json
或者,如果要保留原始结构,请执行以下操作:

$ jq '.categoriesListArr |= fromjson' detail.json

那么你是在写
javascript
shell
还是
php
?shell..正如我上面提到的,但不是你标记的:)第一部分很简单:
jq'.categoriesListArr'detail.json
。不过,我不确定之后如何“解码”字符串。是的,第一部分已经完成。第二部分呢。如何将stringify对象从JSON转换为jsonFYI是在版本1.4中添加的。