0

I built a dynamic Survey type application where users can set up their template of questions/attributes that need to be captured. A template can have multiple sections, where each section contains multiple questions/attributes.

We write out the data in JSON according to the template, to be consumed or sent by webhooks, for external systems. Rather than developing a layer for each external integration to deserialize our system's object and transform it for the external system's consumption, I was thinking of writing dynamic mapper that uses a configuration schema(maybe JSON) that will map your source to your destination. Which will be great, as soon as either the source or destination changes, the configuration can just be adjusted accordingly, without having to change code and re-publish.

I'm using this system as an example, but I'm seeing multiple applications for different use cases, with the main one being a source API that needs to integrate with multiple external API's.

Source JSON example:

{
  "Section1": {
    "S1Attribute1": "S1Attribute1Answer",
    "S1Attribute2": "S1Attribute2Answer",
    "S1Attribute3": "S1Attribute3Answer"
  },
  "Section2": {
    "S2Attribute1": "S2Attribute1Answer",
    "S2Attribute2": "S2Attribute2Answer"
  }
}

Destination 1 Example:

{
  "SectionsFlattened": {
    "S1Attribute1": "S1Attribute1Answer",
    "S1Attribute2": "S1Attribute2Answer",
    "S1Attribute3": "S1Attribute3Answer",
    "S2Attribute1": "S2Attribute1Answer",
    "S2Attribute2": "S2Attribute2Answer"
  }
}

Destination 2 Example:

{
  "NewSection1Name": {
    "NewS1Attribute1Name": "S1Attribute1Answer",
    "NewS1Attribute2Name": "S1Attribute2Answer",
    "NewS1Attribute3Name": "S1Attribute3Answer",
    "NewSection2Name": {
      "NewS2Attribute1Name": "S2Attribute1Answer",
      "NewS2Attribute2Name": "S2Attribute2Answer"
    }
  }
}

This is pretty simple examples of just moving properties around, but the possibilities are endless of how one would need to transform it.

It feels like a problem that somebody would have investigated or solved maybe, but in all my research I don't seem to find anything concrete, or I'm struggling to find a good starting point - maybe I'm approaching the problem incorrectly. Any suggestions/guidance/articles/libraries would be appreciated.

Sagariouz
  • 51
  • 3
  • 1
    This question seems too broad for stack overflow currently, but maybe see [XSLT equivalent for JSON](https://stackoverflow.com/q/1618038/3744182) and https://www.saxonica.com/papers/xmlprague-2016mhk.pdf and https://www.w3.org/TR/xslt-30/#json. – dbc Oct 14 '20 at 18:26
  • Or you could always code each transformation using Json.NET's LINQ to JSON, see e.g. [Modifying JSON](https://www.newtonsoft.com/json/help/html/ModifyJson.htm). – dbc Oct 14 '20 at 18:31
  • @dbc Thank you, I totally forgot about XSLT and it put me on the right track. I ended up choosing this library: https://github.com/WorkMaze/JUST.net – Sagariouz Oct 22 '20 at 06:10

0 Answers0