I've this JSON data, extracted from qbittorrent:
[
  {
    "hash": "333333333333333333333333333",
    "name": "testtosearchcaseinsensitive",
    "magnet_uri": "magnet:somedata",
    "size": 1243989552,
    "progress": 1.0,
    "dlspeed": 0,
    "upspeed": 0,
    "priority": 0,
    "num_seeds": 0,
    "num_complete": 2,
    "num_leechs": 0,
    "num_incomplete": 32,
    "ratio": 0.0,
    "eta": "1.01:11:52",
    "state": "stalledUP",
    "seq_dl": false,
    "f_l_piece_prio": false,
    "category": "category",
    "tags": "",
    "super_seeding": false,
    "force_start": false,
    "save_path": "/data/path/",
    "added_on": 1567358333,
    "completion_on": 1567366287,
    "tracker": "somedata",
    "dl_limit": null,
    "up_limit": null,
    "downloaded": 1244073666,
    "uploaded": 0,
    "downloaded_session": 0,
    "uploaded_session": 0,
    "amount_left": 0,
    "completed": 1243989552,
    "ratio_limit": 1.0,
    "seen_complete": 1567408837,
    "last_activity": 1567366979,
    "time_active": "1.01:00:41",
    "auto_tmm": true,
    "total_size": 1243989552,
    "max_ratio": 1,
    "max_seeding_time": 2880,
    "seeding_time_limit": 2880
  },
  {
    "hash": "44444444444444",
    "name": "dontmatch",
    "magnet_uri": "magnet:somedata",
    "size": 2996838603,
    "progress": 1.0,
    "dlspeed": 0,
    "upspeed": 0,
    "priority": 0,
    "num_seeds": 0,
    "num_complete": 12,
    "num_leechs": 0,
    "num_incomplete": 0,
    "ratio": 0.06452786606740063,
    "eta": "100.00:00:00",
    "state": "stalledUP",
    "seq_dl": false,
    "f_l_piece_prio": false,
    "category": "category",
    "tags": "",
    "super_seeding": false,
    "force_start": false,
    "save_path": "/data/path/",
    "added_on": 1566420155,
    "completion_on": 1566424710,
    "tracker": "some data",
    "dl_limit": null,
    "up_limit": null,
    "downloaded": 0,
    "uploaded": 193379600,
    "downloaded_session": 0,
    "uploaded_session": 0,
    "amount_left": 0,
    "completed": 2996838603,
    "ratio_limit": -2.0,
    "seen_complete": 4294967295,
    "last_activity": 1566811636,
    "time_active": "10.23:07:42",
    "auto_tmm": true,
    "total_size": 2996838603,
    "max_ratio": -1,
    "max_seeding_time": -1,
    "seeding_time_limit": -2
  }
]
So I want to match all data where the name have some text, so, in Bash I write this but I can't make it work.
Some declaration to start, actually I pass data via arguments, so I use $1:
TXTIWANT="test"
MYJSONDATA= Here I put my JSON data
Then this jq equation that doesn't work for me is this:
RESULTS=$(echo "$MYJSONDATA" | jq --raw-output --arg TOSEARCH "$TXTIWANT" '.[] | select(.name|test("$TOSEARCH.";"i")) .name')
But I always got an error or all data, I think because $TOSEARCH is not expanded.
Maybe there's a better way to search a string inside a value?
What I do wrong?
 
     
     
    