Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

Can not extract more than one key when looping over an array with jq in bash [duplicate]

$
0
0

This works:

#!/bin/sh -ecat << EOF > error.json[  {"path": "path1","path_with_namespace": "path_with_namespace1"  },  {"path": "path2","path_with_namespace": "path_with_namespace2"  }]EOFjq -c '.[]' error.json | while read PROJECT; do  # This works  PATH_WITH_NAMESPACE=$(echo "$PROJECT" | jq .path_with_namespace)  echo "Shallow cloning $PATH_WITH_NAMESPACE ..."done

Output:

$ ./error.sh Shallow cloning "path_with_namespace1" ...Shallow cloning "path_with_namespace2" ...

Extracting a second value does not work:

#!/bin/sh -ecat << EOF > error.json[  {"path": "path1","path_with_namespace": "path_with_namespace1"  },  {"path": "path2","path_with_namespace": "path_with_namespace2"  }]EOFjq -c '.[]' error.json | while read PROJECT; do  # This works  PATH_WITH_NAMESPACE=$(echo "$PROJECT" | jq .path_with_namespace)  echo "Shallow cloning $PATH_WITH_NAMESPACE ..."  # This does not  PATH=$(echo "$PROJECT" | jq .path)  echo "$PATH"done

Output:

$ ./error.sh Shallow cloning "path_with_namespace1" ..."path1"./error.sh: line 18: jq: command not found

I've tried numerous variants of looping over arrays with bash and jq. Basically I can't work with more than one key out of the json file. I need to work with more than one. How would a solution look like?

@0stone0 quoting "$PROJECT" has no effect.


Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>