在 shell 脚本中使用 jq 过滤器从 stringify 对象获取 json 对象
get json object from stringify object using jq filter in shell script
我正在编写 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 过滤器转换它
fromjson 是你的朋友:
$ jq '.categoriesListArr | fromjson' detail.json
或者,如果你想保留原来的结构:
$ jq '.categoriesListArr |= fromjson' detail.json
我正在编写 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 过滤器转换它
fromjson 是你的朋友:
$ jq '.categoriesListArr | fromjson' detail.json
或者,如果你想保留原来的结构:
$ jq '.categoriesListArr |= fromjson' detail.json