Skip to main content

Hi team

i have column 

request_param:

0:

   a : “11”

   b: “12”

   c: “12”

   d: “12”

 

how i can get count if above request has 4 parameter it can have 3 also like below

request_param:

0:

   a : “11”

   b: “12”

   c: “12”

 

based on count i need to hit diff url

 

@Bikram  any suggestion?


@akanshajain6793 

Kindly provide me the sample data ,so i can try to get the number of parameters in it.


@Bikram  above is the data i have

 

first request -

request_param:

0:

   a : “11”

   b: “12”

   c: “12”

   d: “12”

 

second request -

request_param:

0:

   a : “11”

   b: “12”

   c: “12”

  


@akanshajain6793 

If the request_param  is a map , can you please try to get the size of the map using size(request_param) in expression evaluator.

If you can provide me the actual parameter ,so i can try to help you.

The above parameters seems like dummy one but i want the json data which will help me to reproduce the issue.

 

You also can try to get the size of the map in jython evaluator and proceed further.

 

Thanks & Regards

Bikram_

 

 


@akanshajain6793

 

Please flatten the nested json and use the below code to get the parameter count in your pipeline.

 

   

#newRecord = sdcFunctions.createRecord('header')

val = ''
## Sample Jython code
for record in sdc.records:
  try:
    count = 0
    for key in record.value:
      count += 1
      record.value = {"txt":count}
      
    sdc.output.write(record) 
    # Write record to processor output
    
    

  except Exception as e:
    # Send record to error
    sdc.error.write(record, str(e))
    sdc.output.write(recor


@akanshajain6793 

You can use Expression Evaluator.

 

${ length( record:value('/f1'))}

 

If field f1 holds 4 values then the above expression will return 4.

 

 


as @Bikram  suggested, use size() function of you want to get the number of attributes in a MAP

or use length if you want to count number of items in a LIST


Reply