Pass string from python to parse json array in tigergraph

CREATE QUERY ageBasedSegment(String str) FOR GRAPH clientA_analytic { 
  /* Write query logic here */ 
  JSONARRAY arr;
  arr = parse_json_array(str);
  DATETIME today = now();
  
  
  foreach ageindx in range[0,arr.size()-1] do
      STRING agekey= arr.getJsonObject(ageindx).getString("name");
      STRING agevalue=arr.getJsonObject(ageindx).getString("value");
      if instr(agevalue, "below") != -1 THEN
                 # Below Found
                 #begin = substr(value,0, instr(value, " "));
                 STRING lastagevalue = substr(agevalue,instr(agevalue, " ")+1, length(agevalue));
                 age_filter_customers = select s from customer:s where 
                            floor((datetime_diff(today, s.dob)/86400)/365.2425) <= str_to_int(lastagevalue);
      else if instr(agevalue, "-") != -1 THEN
                   # in between case
                   STRING beginagevalue = substr(agevalue,0, instr(agevalue, "-"));
                   STRING lastagevalue = substr(agevalue,instr(agevalue, "-")+1, length(agevalue));
  
                   age_filter_customers = select s from customer:s where 
                          floor((datetime_diff(today, s.dob)/86400)/365.2425) >= str_to_int(beginagevalue) 
                                  and floor((datetime_diff(today, s.dob)/86400)/365.2425) <=                                                         str_to_int(lastagevalue);
      else if instr(agevalue, "above") != -1 THEN
                    # Above Case
                    STRING lastagevalue = substr(agevalue,instr(agevalue, " ")+1, length(agevalue));
                    age_filter_customers = select s from customer:s where 
                         floor((datetime_diff(today, s.dob)/86400)/365.2425) <= str_to_int(lastagevalue);
      end;
      age_filter_customers = select s from age_filter_customers:s POST-ACCUM
                      INSERT INTO segment_types (PRIMARY_ID, label) 
                         VALUES ("ageBasedSegments", "Age Based Segments"),
                    INSERT INTO profile_attribute_segment (PRIMARY_ID, label) VALUES (agekey, agekey),
                    Insert into segment_profile_attribute_segment(FROM, To) VALUES("ageBasedSegments", agekey),
                    INSERT into customer_profile_attribute_segment (FROM, TO) VALUES (s.customer_id, agekey);

end;
  
   
}

here is there any other way in tigergraph to handle this:
another i need to create a lots of logic in python make it like this

https://dev.tigergraph.com/forum/t/pass-string-to-parse-it-as-jsonarray/870/3

cant we can send like this "[{“name”: “Tenagers (<18)”, “value”: “below 18”}]"

RUN QUERY test_age_based("[{\“name\”: \“Tenagers (<18)\”, \“value\”:\“below 18\”}]")