Question
· Aug 26

Best practices for JSON transformation in IRIS interoperability

What are best practices for JSON transformation in IRIS interoperability? This is for a non-healthcare use case, so any tools we happen to have around FHIR might not be available. The motivating use case is trimming down a verbose and needlessly complex REST API response to feed to an LLM - trying to reduce token usage and maybe get better results from less noisy data.

Specifically, I'm imagining matching based on JSONPath expressions and simplifying structures based on the inferred type of elements rather than a full schema. This might look replacing a deeply nested object value with a string from one of its subfields, stripping out some fields, removing keys where all values underneath are null, etc.

If there aren't good answers I'll build my own approach.

Product version: IRIS 2025.1
Discussion (5)3
Log in or sign up to continue

Ended up writing my own based on https://github.com/intersystems/isc-json/blob/main/cls/_pkg/isc/json/path.cls which implements https://goessner.net/articles/JsonPath/ - syntax looks like this, where inputObject and result are both %DynamicAbstractObjects:

    Set result = ##class(%pkg.isc.json.transformer).For(inputObject
        ).Remove("$..url" // Remove URL
        ).Remove("$..requested_fields" // Remove requested_fields
        ).Remove("$..[?($IsObject(@) && (@.%Size() = 0))]" // Remove empty arrays/objects
        ).Remove("$..[?($IsObject(@) && (@.%Size() = 1) && (@.%GetTypeOf(1) = ""null""))]" // Remove one-element arrays containing only a null
        ).TransformElement("$..issue_type","$.name" // Replace issue type object with just the name
        ).TransformElement("$..priority","$.name" // Replace priority object with just the name
        ).TransformElement("$..status","$.name" // Replace status object with just the name
        ).TransformElement("$..[?($IsObject(@) && @.%IsA(""%DynamicObject"") && (@.""avatar_url"" '= """"))]","$.display_name" // Replace any user (indicated by avatar_url) with just the user's display name
        ).GetResult()

I'll probably get this into https://github.com/intersystems/isc-json at some point (subject to some process hurdles); if you're interested nag me here / via DM.