Best way to convert HKQuantitySample to JSON to send to a web service

I have an array of HKQuantitySample and I'd like to convert it to JSON to POST it to a web service. Are there any tools or best practices to make this easy?

I've seen a couple of different examples where the code takes pieces of data off of HKQuantitySample (or any HKSample) and sends only those pieces -- usually just the value.

What if I want the entire HKQuantitySample object?

Today, I have code that uses an Extension to apply Encodable and then I implement encode(to:) to capture the fields up the object hierarchy. Encodable makes that easy, but I feel like I'm inventing the wheel. I also have to cast HKSample to the subtypes to make it work -- not a problem, but definitely an extra step.

Has anyone else already solved this problem? Any recommendations or suggestions?
Best way to convert HKQuantitySample to JSON to send to a web service
 
 
Q