JQ command to retrieve just the titles
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have this json file:
"["id":188457,"title":"Painted Dragon Tea Mug with Lid","slug":"painted-dragon-tea-mug-with-lid","image":"https:\/\/thievemedia.imgix.net\/2018\/09\/painted-dragon-tea-mug-with-lid-featured-1.jpg","full_image_url":"https:\/\/s3.amazonaws.com\/thieve-media\/wp-content\/uploads\/2018\/09\/painted-dragon-tea-mug-with-lid-featured-1.jpg","large_image_url":"https:\/\/s3.amazonaws.com\/thieve-media\/wp-content\/uploads\/2018\/09\/painted-dragon-tea-mug-with-lid-featured-1.jpg","medium_image_url":"https:\/\/s3.amazonaws.com\/thieve-media\/wp-content\/uploads\/2018\/09\/painted-dragon-tea-mug-with-lid-featured-1.jpg","original_price":"19.78","price":"13.65","discount":"30.99","rating":"4.7","total_orders":"10","promotion_url":"https:\/\/api.thieve.co\/view?id=MzI4NTk0Njg0MDE=","product_like_count":"100","product_user_likes"]
How can I extract only the titles with jq?
jq
add a comment |Â
up vote
0
down vote
favorite
I have this json file:
"["id":188457,"title":"Painted Dragon Tea Mug with Lid","slug":"painted-dragon-tea-mug-with-lid","image":"https:\/\/thievemedia.imgix.net\/2018\/09\/painted-dragon-tea-mug-with-lid-featured-1.jpg","full_image_url":"https:\/\/s3.amazonaws.com\/thieve-media\/wp-content\/uploads\/2018\/09\/painted-dragon-tea-mug-with-lid-featured-1.jpg","large_image_url":"https:\/\/s3.amazonaws.com\/thieve-media\/wp-content\/uploads\/2018\/09\/painted-dragon-tea-mug-with-lid-featured-1.jpg","medium_image_url":"https:\/\/s3.amazonaws.com\/thieve-media\/wp-content\/uploads\/2018\/09\/painted-dragon-tea-mug-with-lid-featured-1.jpg","original_price":"19.78","price":"13.65","discount":"30.99","rating":"4.7","total_orders":"10","promotion_url":"https:\/\/api.thieve.co\/view?id=MzI4NTk0Njg0MDE=","product_like_count":"100","product_user_likes"]
How can I extract only the titles with jq?
jq
That's not valid JSON -- it is a JS string containing escape sequences, so you'll first have to remove those escapes with eg.sed 's/^"//;s/"$//;s/\(.)/1/g'
â JigglyNaga
7 hours ago
Thank you! It worked!
â Kerim Güleç
6 hours ago
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have this json file:
"["id":188457,"title":"Painted Dragon Tea Mug with Lid","slug":"painted-dragon-tea-mug-with-lid","image":"https:\/\/thievemedia.imgix.net\/2018\/09\/painted-dragon-tea-mug-with-lid-featured-1.jpg","full_image_url":"https:\/\/s3.amazonaws.com\/thieve-media\/wp-content\/uploads\/2018\/09\/painted-dragon-tea-mug-with-lid-featured-1.jpg","large_image_url":"https:\/\/s3.amazonaws.com\/thieve-media\/wp-content\/uploads\/2018\/09\/painted-dragon-tea-mug-with-lid-featured-1.jpg","medium_image_url":"https:\/\/s3.amazonaws.com\/thieve-media\/wp-content\/uploads\/2018\/09\/painted-dragon-tea-mug-with-lid-featured-1.jpg","original_price":"19.78","price":"13.65","discount":"30.99","rating":"4.7","total_orders":"10","promotion_url":"https:\/\/api.thieve.co\/view?id=MzI4NTk0Njg0MDE=","product_like_count":"100","product_user_likes"]
How can I extract only the titles with jq?
jq
I have this json file:
"["id":188457,"title":"Painted Dragon Tea Mug with Lid","slug":"painted-dragon-tea-mug-with-lid","image":"https:\/\/thievemedia.imgix.net\/2018\/09\/painted-dragon-tea-mug-with-lid-featured-1.jpg","full_image_url":"https:\/\/s3.amazonaws.com\/thieve-media\/wp-content\/uploads\/2018\/09\/painted-dragon-tea-mug-with-lid-featured-1.jpg","large_image_url":"https:\/\/s3.amazonaws.com\/thieve-media\/wp-content\/uploads\/2018\/09\/painted-dragon-tea-mug-with-lid-featured-1.jpg","medium_image_url":"https:\/\/s3.amazonaws.com\/thieve-media\/wp-content\/uploads\/2018\/09\/painted-dragon-tea-mug-with-lid-featured-1.jpg","original_price":"19.78","price":"13.65","discount":"30.99","rating":"4.7","total_orders":"10","promotion_url":"https:\/\/api.thieve.co\/view?id=MzI4NTk0Njg0MDE=","product_like_count":"100","product_user_likes"]
How can I extract only the titles with jq?
jq
jq
edited 8 hours ago
Jeff Schaller
33.8k851113
33.8k851113
asked 9 hours ago
Kerim Güleç
61
61
That's not valid JSON -- it is a JS string containing escape sequences, so you'll first have to remove those escapes with eg.sed 's/^"//;s/"$//;s/\(.)/1/g'
â JigglyNaga
7 hours ago
Thank you! It worked!
â Kerim Güleç
6 hours ago
add a comment |Â
That's not valid JSON -- it is a JS string containing escape sequences, so you'll first have to remove those escapes with eg.sed 's/^"//;s/"$//;s/\(.)/1/g'
â JigglyNaga
7 hours ago
Thank you! It worked!
â Kerim Güleç
6 hours ago
That's not valid JSON -- it is a JS string containing escape sequences, so you'll first have to remove those escapes with eg.
sed 's/^"//;s/"$//;s/\(.)/1/g'
â JigglyNaga
7 hours ago
That's not valid JSON -- it is a JS string containing escape sequences, so you'll first have to remove those escapes with eg.
sed 's/^"//;s/"$//;s/\(.)/1/g'
â JigglyNaga
7 hours ago
Thank you! It worked!
â Kerim Güleç
6 hours ago
Thank you! It worked!
â Kerim Güleç
6 hours ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
The query '. | title'
will give you just the title elements (but note that your sample document seems to be malformed), assuming your document is in a file called data.json
:
$ jq '. | title' data.json
"title": "Painted Dragon Tea Mug with Lid"
The first part of the query, '.'
, returns each object in the top-level array, and these are then sent to the second part, using the |
operator. The second part of the query, title
, simply extracts the "title" element from the object.
If you want just the title, as a string, without wrapping the results in a JSON object, use this instead:
$ jq '. | .["title"]' data.json
"Painted Dragon Tea Mug with Lid"
The jq
tutorial offers a good overview of the query language.
Thank you for your reply. The original file is at api.thieve.co/wp-json/thieve/v1/products/?category-name=/⦠but I'm getting an error :(
â Kerim Güleç
7 hours ago
You can shorten the expression to..title
.
â JigglyNaga
7 hours ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
The query '. | title'
will give you just the title elements (but note that your sample document seems to be malformed), assuming your document is in a file called data.json
:
$ jq '. | title' data.json
"title": "Painted Dragon Tea Mug with Lid"
The first part of the query, '.'
, returns each object in the top-level array, and these are then sent to the second part, using the |
operator. The second part of the query, title
, simply extracts the "title" element from the object.
If you want just the title, as a string, without wrapping the results in a JSON object, use this instead:
$ jq '. | .["title"]' data.json
"Painted Dragon Tea Mug with Lid"
The jq
tutorial offers a good overview of the query language.
Thank you for your reply. The original file is at api.thieve.co/wp-json/thieve/v1/products/?category-name=/⦠but I'm getting an error :(
â Kerim Güleç
7 hours ago
You can shorten the expression to..title
.
â JigglyNaga
7 hours ago
add a comment |Â
up vote
2
down vote
The query '. | title'
will give you just the title elements (but note that your sample document seems to be malformed), assuming your document is in a file called data.json
:
$ jq '. | title' data.json
"title": "Painted Dragon Tea Mug with Lid"
The first part of the query, '.'
, returns each object in the top-level array, and these are then sent to the second part, using the |
operator. The second part of the query, title
, simply extracts the "title" element from the object.
If you want just the title, as a string, without wrapping the results in a JSON object, use this instead:
$ jq '. | .["title"]' data.json
"Painted Dragon Tea Mug with Lid"
The jq
tutorial offers a good overview of the query language.
Thank you for your reply. The original file is at api.thieve.co/wp-json/thieve/v1/products/?category-name=/⦠but I'm getting an error :(
â Kerim Güleç
7 hours ago
You can shorten the expression to..title
.
â JigglyNaga
7 hours ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
The query '. | title'
will give you just the title elements (but note that your sample document seems to be malformed), assuming your document is in a file called data.json
:
$ jq '. | title' data.json
"title": "Painted Dragon Tea Mug with Lid"
The first part of the query, '.'
, returns each object in the top-level array, and these are then sent to the second part, using the |
operator. The second part of the query, title
, simply extracts the "title" element from the object.
If you want just the title, as a string, without wrapping the results in a JSON object, use this instead:
$ jq '. | .["title"]' data.json
"Painted Dragon Tea Mug with Lid"
The jq
tutorial offers a good overview of the query language.
The query '. | title'
will give you just the title elements (but note that your sample document seems to be malformed), assuming your document is in a file called data.json
:
$ jq '. | title' data.json
"title": "Painted Dragon Tea Mug with Lid"
The first part of the query, '.'
, returns each object in the top-level array, and these are then sent to the second part, using the |
operator. The second part of the query, title
, simply extracts the "title" element from the object.
If you want just the title, as a string, without wrapping the results in a JSON object, use this instead:
$ jq '. | .["title"]' data.json
"Painted Dragon Tea Mug with Lid"
The jq
tutorial offers a good overview of the query language.
answered 7 hours ago
D_Bye
10.2k13026
10.2k13026
Thank you for your reply. The original file is at api.thieve.co/wp-json/thieve/v1/products/?category-name=/⦠but I'm getting an error :(
â Kerim Güleç
7 hours ago
You can shorten the expression to..title
.
â JigglyNaga
7 hours ago
add a comment |Â
Thank you for your reply. The original file is at api.thieve.co/wp-json/thieve/v1/products/?category-name=/⦠but I'm getting an error :(
â Kerim Güleç
7 hours ago
You can shorten the expression to..title
.
â JigglyNaga
7 hours ago
Thank you for your reply. The original file is at api.thieve.co/wp-json/thieve/v1/products/?category-name=/⦠but I'm getting an error :(
â Kerim Güleç
7 hours ago
Thank you for your reply. The original file is at api.thieve.co/wp-json/thieve/v1/products/?category-name=/⦠but I'm getting an error :(
â Kerim Güleç
7 hours ago
You can shorten the expression to
..title
.â JigglyNaga
7 hours ago
You can shorten the expression to
..title
.â JigglyNaga
7 hours ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474295%2fjq-command-to-retrieve-just-the-titles%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
That's not valid JSON -- it is a JS string containing escape sequences, so you'll first have to remove those escapes with eg.
sed 's/^"//;s/"$//;s/\(.)/1/g'
â JigglyNaga
7 hours ago
Thank you! It worked!
â Kerim Güleç
6 hours ago