Skip to main content

inputdata:

I want to change all keys are in same:-

like 0,1,2, keys are changed to $id for all how to fix this ..suggest .

 

@lakshmi_narayanan_t 

 

Can you please check if the below code snippet will resolve the issue or not ?

Please use it in jython evaluator processor.

import json
json_str = '{"0":10456.89,"1":10456.89,"2":10456.89,"3":10456.89,"4":10456.89,"5":10456.89,"6":10567.89,"7":10678.89,"8":10899.89,"9":10999.89}'
#new_dict = {}

# Sample Jython code
for record in sdc.records:
  try:
    data_dict = json.loads(json_str)
    #s1 =  #fun(data_dict)
    s1 =  {"id":val} for val in data_dict.values()] 
    record.value 'data1'] = json.dumps(s1)
    # Write record to processor output
    sdc.output.write(record)

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


@lakshmi_narayanan_t

 

Can you please check if the below code snippet will resolve the issue or not ?

Please use it in jython evaluator processor.

import json
json_str = '{"0":10456.89,"1":10456.89,"2":10456.89,"3":10456.89,"4":10456.89,"5":10456.89,"6":10567.89,"7":10678.89,"8":10899.89,"9":10999.89}'
#new_dict = {}

# Sample Jython code
for record in sdc.records:
  try:
    data_dict = json.loads(json_str)
    #s1 =  #fun(data_dict)
    s1 = {"id":val} for val in data_dict.values()] 
    record.valuer'data1'] = json.dumps(s1)
    # Write record to processor output
    sdc.output.write(record)

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

how can i give field of values  to this jypthon  evaluvator.


@lakshmi_narayanan_t 

 

Please try the below ode snippet and let. me know if it. helps.

import json

for record in sdc.records:
  try:

     
    data_dict = json.loads(record.valuer'assigned_to'])
    #s1 =  #fun(data_dict)
    s1 = /{"id":val} for val in data_dict.values()] 
    record.value 'data1'] = json.dumps(s1)
    # Write record to processor output
    sdc.output.write(record)  except Exception as e:
    # Send record to error
    sdc.error.write(record, str(e))


Reply