Ask Your Question
0

Creating Nested JSON [closed]

asked 2021-04-13 14:27:36 -0500

Faiyazy gravatar image

updated 2021-04-13 14:55:13 -0500

My Origin is JDBC Consumer: SELECT key, name, summary, text1, text2, text3 from TableA

Query results returns: key, name, summary, text1, text2, text3

123, task, "check the email from abc@abc.com, call me back", Abc, abc2, xyz

124, task, "respond to email", abc, avc, hvac

Desired JSON output: { "fields": { "project": { "key": "123" }, "issuetype": { "name": "Task" },
"summary": "check the email from abc@abc.com", "text1" : "Abc",
"text2" : "abc2", "text3" : "xyz" }, "fields": { "project": { "key": "124" }, "issuetype": { "name": "Task" },
"summary": "respond to the email from xyz@abc.com", "text1" : "abcd",
"text2" : "abc2", "text3" : "abcxyz" }
}

Was able to get to this point using expression evaluator with emptymap: JSON output:

{ "fields": { "key": "123" "name": "Task" "summary": "check the email from abc@abc.com", "text1" : "Abc",
"text2" : "abc2", "text3" : "xyz" }, "fields": { "key": "124" "name": "Task" "summary": "respond to the email from xyz@abc.com", "text1" : "abcd",
"text2" : "abc2", "text3" : "abcxyz" }
}

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Faiyazy
close date 2021-04-15 16:12:45.575372

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-04-15 16:12:02 -0500

Faiyazy gravatar image

I was able to solve this using Jython Evaluator, by hard coding key values and nesting to meet my needs:

for record in sdc.records: try: newRecord = sdc.createRecord(record.sourceId + ':newRecordId') newRecord.value = {"update": {},"fields": {'project' : {'key': record.value['Keyword']}, 'issuetype' : {'name': record.value['Taskword']}, 'text1': record.value['text1'], 'text2': record.value['text2'], 'text3': record.value['text3'], 'summary': record.value['Summary_Text']}} sdc.output.write(newRecord)

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

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-04-13 14:27:36 -0500

Seen: 80 times

Last updated: Apr 15