Closed bleleve closed 1 year ago
This is because
yq '.registry.npm.deps[]'
Doesn't produce valid YAML - the output is:
package: '@grpc/grpc-js'
version: '^1.8.0'
package: 'google-protobuf'
version: '^3.21.2'
Where as if you output as json - it produces valid NDJSON - which can be read by both jq
and yq
(if you tell it to read json via -pj
.
To product a valid yaml doc, move the splat to the second command, so that the first still produces a valid doc:
yq '.registry.npm.deps' data1.yaml | ./yq '.[] | .package + "@" + .version'
@grpc/grpc-js@^1.8.0
google-protobuf@^3.21.2
Note: -r
is default true in yq
, so you only need to specify -r=false
if you don't want it :)
Edit: fixed command
Also, you can of course do this in a single line:
yq '.registry.npm.deps[].package + "@" + .version' data1.yaml
Thank you Mike ;)
Note: the single line is like this yq '.registry.npm.deps | .[] | .package + "@" + .version'
otherwise we have the same problem.
Best regards.
Version of yq: 4.31.1 Operating system: wsl windows Installed via: binary release
Input Yaml bufbuild_grpc_node.yml:
Command The command you ran:
Actual behavior
Expected behavior
Additional context This is working as expected using jq :