For example:
echo '{"p":2}{"q":3}' | jq '.'
How do I select the first object? I want the object below:
{"p":2}
You would use the -n command-line option, e.g.:
jq -n input
or
jq -n 'first(inputs)'
echo '{"p":2}{"q":3}' | jq -n 'first(inputs)' works. Thank you.echo '{"p":2}{"q":3}{"r":4}{"s":5}{"t":6}' | jq -n 'nth(2;inputs)' -> {"r":4}echo '{"p":2}{"q":3}{"r":4}{"s":5}{"t":6}' | jq --slurp '.[2]' also works!jq --slurp '.[2]' also works", yeah, jq --slurp '...' is the same as jq -n '[ inputs ] | ...' These aren't as good as using first and nth as they require loading the entire stream into memory at once.
{}, or it was a just a placeholder to contain some meaningful input inside{}is a valid JSON object.