Solved

how to change key names are in same names in json data..

  • 30 March 2023
  • 3 replies
  • 32 views

Userlevel 2

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 .

 

icon

Best answer by Bikram 30 March 2023, 18:35

View original

3 replies

Userlevel 5
Badge +1

@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))

Userlevel 2

@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))

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

Userlevel 5
Badge +1

@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.value['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