Attached is an example of using the json.dumps() method to create a serialized json string from field data.
The API and Script bindings section of the Help documentation describes the use of the fields.todict() method used in the example.
You may also find this article useful https://stackabuse.com/reading-and-writing-json-to-a-file-in-python/
The example only combines the data for a single transaction so in priactice you would need to combine the header data, refund data and salesforce case data for each transaction into a single record and then acculate all of the transaction data in a list before serializing the overall json object.
Attached files
Output_JSON_Transactions--share - 12 Oct 2020.lna