Reputation: 595
Here is the jq
command like below: jq '.. |."$ref"? | select(. != null)'
It works in jq player
How do I run this command in Powershell?
I want to get all returned values to a variable in PowerShell (list/array).
I have tried:
jq '.. |.'$ref'? | select(. != null)' .\swagger.json
--> I get everything in json file.jq '.. |."$ref"? | select(. != null)' .\swagger.json
--> jq: error: syntax error, unexpected '$' (Windows cmd shell quoting issues?) at , line 1:
.. |.$ref? | select(. != null)How to get this jq command to work in Powershell? Thanks
Upvotes: 0
Views: 1923
Reputation: 265707
jq '.. |.\"$ref\"? | select(. != null)'
works with PowerShell version 5.1.1941.1682 on Windows 10. Note the single quotes around the argument and the backslashes before the double quotes.
If it doesn't, create a text file with the jq program (the string inside the quotes) and then run jq -f program.jq
. This avoids any quoting or escaping issues of your shell, you can write the jq program verbatim, just as you would on jq play.
NB: select(. != null)
can be written more succinctly as select(values)
Upvotes: 0