Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get json object from stringify object using jq filter in shell script

Tags:

json

linux

shell

jq

i am wring the shell script as i am new. my query is i have json object like

{
   "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"
}

i extracted the categoriesListArr using jq filter as follows:

categories=`cat detail.json| jq '.categoriesListArr'`

detail.json is the name of the file. now categories is stringify object...i need to parse it and convert it into json object.

"{\"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\"]}"

how i can convert it using jq filter

like image 649
Ranjit Singh Avatar asked Sep 17 '15 11:09

Ranjit Singh


1 Answers

fromjson is your friend:

$ jq '.categoriesListArr | fromjson' detail.json

Or, if you want to retain the original structure:

$ jq '.categoriesListArr |= fromjson' detail.json
like image 96
peak Avatar answered Nov 05 '22 13:11

peak