Logan Lee
Logan Lee

Reputation: 997

Passing string rather than filename to -f option in jq under bash

I'm curious whether I can replace file name with a string when using -f option of jq.

When I do

$ jq -nf <(echo \"hello world\")

it correctly outputs

"hello world"

But when I try

$ jq -nf <<<$'\"hello world\"'

this fails with error

jq: Could not open .: It's a directory

Anyone knows how to make this work? I know this is more of a bash question than jq.

$ jq '.' <<< '"hello world"' works though.

Thanks.

Upvotes: 0

Views: 338

Answers (1)

KamilCuk
KamilCuk

Reputation: 141698

You can use /dev/stdin to represent standard input as a file:

jq -nf /dev/stdin <<<$'\"hello world\"'
echo \"hello world\" | jq -nf /dev/stdin

Upvotes: 2

Related Questions