Reputation: 77
Website https://sites.research.google/versebyverse/ can generate poems automatically.
I want to get them to Linux console.
I have inspected this website with Firefox and found, that it uses GET and POST and JSON.
I have selected such parameters:
I have made curl request and saved it to variable:
verses=$(curl -k 'https://sites.research.google/versebyverse/api/PoemFrontendService/GenerateVerses' --compressed -H 'Content-Type: application/json' -H 'Origin: https://sites.research.google' -H 'Connection: keep-alive' -H 'Referer: https://sites.research.google/versebyverse/' --data-raw '{"dependency":"The sheer wall","numberOfVerses":5,"poetKey":["edgar_allan_poe"],"samplingSize":10,"syllableCount":"7"}' )
Now I want to parse it with jq. But I have no ided how to do it with one command.
I came only to this:
echo "$verses" | jq .verse | jq '[.[]|select(.text)][0]' | jq -r .text
And that gave me:
Held me at my many home—
That's fine but I need to have only one jq for better code. Please help me to make this with just one jq.
I need to select the result of text and only the first one. Or random one if it's possible.
Upvotes: 1
Views: 45
Reputation: 88776
I suggest:
echo "$verses" | jq -r '.verse[1].text'
Output:
Held me at the golden door.
Upvotes: 2