JQ command to retrieve just the titles

The name of the pictureThe name of the pictureThe name of the pictureClash 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?










share|improve this question























  • 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














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?










share|improve this question























  • 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












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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • 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










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.






share|improve this answer




















  • 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










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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.






share|improve this answer




















  • 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














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.






share|improve this answer




















  • 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












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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










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
















  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay