Get input output connections

I am trying to create a plug-in that exports the expression graph of a material as a JSON file in a way such that a similar shader can be re-constructed in Maya.
I am working with the C++ api but Python would work too.

I have run into a problem in exporting information on what node attributes are connected to which node attributes. I have a general method that for a given expression I can export the names of the individual input expressions, but I need to know to what parameter that input expression corresponds to.

eg: A Lerp expression takes a texures sample expression’s ‘G’ output as its ‘Alpha’ input parameter.

It seems possible to do this by writing code for each individual expression class and exporting information about its variables, but is there a general way to do this that avoids code for each class?

Any help is greatly appreciated.