Jul-08-2022, 04:14 PM
Using python I want to split a json file into multiple files based on the "transactionTypeName" within the transacations.details. In each file I want the rest of the details as well starting from careperson to username. Below is the json file. Had to clean up the values. Need help with the code suggestion/direction. Thanks in advance.
Learning python I have some idea how to read the json nodes using json.loads. But need help with splitting the json files.
Learning python I have some idea how to read the json nodes using json.loads. But need help with splitting the json files.
{ "careperson": { "FirstName": "tryy", "LastName": "dbdfb" }, "activityDate": "2000-06-14T15:35:00", "locationAddress": { "Address1": "123g hrtjrtt", "City": "Turrty", "State": "AF", "Zip": "56577" }, "siteName": "Trwtyjj", "transactions": [ { "details": [ { "expiration": "2002-08-03T23:59:59", "to_sitelocationId": 0 } ], "transactionType": 6, "transactionTypeName": "Can" }, { "details": [ { "expiration": "2002-08-03T23:59:59", "to_sitelocationId": 0 } ], "transactionType": 6, "transactionTypeName": "Worm" }, { "details": [ { "expiration": "2002-08-03T23:59:59", "to_sitelocationId": 0 } ], "transactionType": 6, "transactionTypeName": "Use" } ], "sbscrberId": 3344, "sbscrber": "sdg" }I want it to split like this. Basically, "Can", "Worm" and "Use" will be separate files. Below is the expected output for "Worm". "Can" and "Use" will look similar. In this example there are 3 transactionTypes but there can be more for other files so I want to make it dynamic.
{ "careperson": { "FirstName": "tryy", "LastName": "dbdfb" }, "activityDate": "2000-06-14T15:35:00", "locationAddress": { "Address1": "123g hrtjrtt", "City": "Turrty", "State": "AF", "Zip": "56577" }, "siteName": "Trwtyjj", "transactions": [ { "details": [ { "expiration": "2002-08-03T23:59:59", "to_sitelocationId": 0 } ], "transactionType": 6, "transactionTypeName": "Worm" } ], "sbscrberId": 3344, "sbscrber": "sdg" }