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

jq how to create a dynamic select list

$
0
0

I'm wondering how you can I create a dynamic select statement to be used with jq. I want to be able to search a result based on names of people that I provide to my script. e.g.

qa_assigned_from_to_me=""IFS=';' read -r -A jira_name_qa_all_array <<< "$jira_name_qa_all"for jira_name_qa in "${jira_name_qa_all_array[@]}"; do  if [[ "$qa_assigned_from_to_me" == "" ]]; then    qa_assigned_from_to_me="(.fromString == \"${jira_name_qa}\" and .toString == \"${jira_name_me}\")"  else    qa_assigned_from_to_me="${qa_assigned_from_to_me} or (.fromString == \"${jira_name_qa}\" and .toString == \"${jira_name_me}\")"  fidonelast_qa_assigned_to_me=$(jq \  --arg qa_assigned_from_to_me $qa_assigned_from_to_me \  -r '[    .values    | sort_by(.id)    | reverse    | .[].items[]    | select(      .field == "assignee"      and (        $qa_assigned_from_to_me      )    )  ]  | first  | .fromString' \"$tmp_response_file")

however this doesn't use the dynamically created select statement in place, instead it seems to just ignore it completely.

When I check the result of the statement created using:

last_qa_assigned_to_me=$(jq -n --arg qa_assigned_from_to_me $qa_assigned_from_to_me '$qa_assigned_from_to_me')echo "last_qa_assigned_to_me: $last_qa_assigned_to_me"

It returns a quoted (") string, so I'm wondering if it's quoting it in the select statement and basically just ignoring it as a condition?

Sample of $qa_assigned_from_to_me

(.fromString == "Person A" and .toString == "Person B")

Here is a sample $tmp_response_file

{"values": [    {"id": "1","items": [        {"fromString": "Person A","toString": "Person B"        }      ]    },    {"id": "2","items": [        {"fromString": "Person B","toString": "Person A"        }      ]    },    {"id": "3","items": [        {"fromString": "Person C","toString": "Person D"        }      ]    }  ]}

Viewing all articles
Browse latest Browse all 657

Trending Articles



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