我正在拧我的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是文件的名称。 现在类别是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过滤器转换它
答案 0 :(得分:5)
fromjson 是你的朋友:
$ jq '.categoriesListArr | fromjson' detail.json
或者,如果您想保留原始结构:
$ jq '.categoriesListArr |= fromjson' detail.json