How to pass the TargetVertex name dynamically in GSQL

CREATE QUERY account_matchingv3(vertex<AM_CUSTOMER> input_acc, String str) FOR GRAPH retail_graph { 
  /* Write query logic here */ 
  start = {input_acc};
  JSONOBJECT jsonobj;
  JSONARRAY arr;
  jsonobj = parse_json_object(str);
  arr = jsonobj.getJsonArray("vertex_weights");
  foreach i in range[0, arr.size()-1] DO
      #PRINT arr.getJsonObject(i).getString("name");
      #  this name contains "AM_EMAIL"
      attributes = SELECT t FROM start:s-(:e)-arr.getJsonObject(i).getString("name"):t;
      
  end;

}

In the above code im getting errror on this line
“arr.getJsonObject(i).getString(“name”)”
how to pass the target vertex name dynamically in tigergraph ?

below my requested input for str

{"vertex_weights": 
      [{"name": "AM_EMAIL",
         "weight": 0.6},
       {"name": "AM_CONTACT",
         "weight": 0.6},
       {"name": "AM_ADDRESS",
         "weight": 0.3}], 
"attributes_weights": 
      [{"name": "first_name",
        "weight": 0.2},
       {"name": "last_name",
        "weight": 0.2},
       {"name": "dob",
        "weight": 0.2}
      ]
}

Hi @Puneet2

You would have to use a SetAccum and a vertex set in that case. You can see the example usage in the modified query below. I marked added lines and the modified line with a comment.

CREATE QUERY account_matchingv3(vertex<AM_CUSTOMER> input_acc, String str) FOR GRAPH retail_graph { 
  /* Write query logic here */ 
  SetAccum<STRING> @@target_vertex_names;  // added line
  start = {input_acc};
  JSONOBJECT jsonobj;
  JSONARRAY arr;
  jsonobj = parse_json_object(str);
  arr = jsonobj.getJsonArray("vertex_weights");
  foreach i in range[0, arr.size()-1] DO
      @@target_vertex_names += arr.getJsonObject(i).getString("name");    // added line
      target_vertex_set = {@@target_vertex_names};    // added line
      attributes = SELECT t FROM start:s-(:e)-target_vertex_set:t;    // modified line
      
      @@target_vertex_names.clear();    // added line
  end;
}

I hope that helps!

Best,
Supawish Limprasert (Jim)
Solution Engineer, TigerGraph