Skip to main content

JDT

Design Considerations for templates per integration​

  • A template is defined per integration (applies to all endpoints of that integration)
    • Ex: If a template is configured for salesforce integration, then all the responses of that integration get transformed based on the template.

Proposed Solutions (Integration)​

Anyone who is aware of JSONPath and Microsoft JDT library should be able to write the templates.
MS-JDT library provides a simple language to transform JSON from one form to another. It gives flexibility such that if we don’t give mapping for any of the fields, it will transform them as it is.

How to achieve transformations:

Here are a few examples we tried out using the JDT library.

1. Merge:

This is a primitive template example to merge the value. Here we are merging the template file with the source file, if there are matching fields, the field in the template file will take precedence. hence we are getting "C": "Replaced", "D": "4".

source filetemplate filefinal file
{ "A": 1, "B": true, "C": null, "D": "4" }{ "A": 10, "B": null, "C": "Replaced" }{ "A": 10, "B": null, "C": "Replaced", "D": "4" }

2. Rename:
If we want to rename the field we can use “@jdt.rename“ which is provided by JDT language, which will rename the field name according to the JSONPath given in “@jdt.path“.

source filetemplate filefinal result
{ "A": 1, "B": true, "C": null, "D": "4" }{ "@jdt.rename": { "@jdt.path": "$.A", "@jdt.value": "Eh" } }{ "Eh": 1, "B": true, "C": null, "D": "4" }
{ "A": [ { "Index": 1 }, { "Index": 2 }, { "Index": 3 } ] }{ "@jdt.rename": { "@jdt.path": "$.A[0,2].Index", "@jdt.value": "Ind" } }{ "A": [ { "Ind": 1 }, { "Index": 2 }, { "Ind": 3 } ] }

We can also apply the condition in JSONPath, in the below example we have a condition inside “@jdt.path“ i.e, “$.B[?(@.Rename == true)].ToChange“.

source filetemplate filefinal result
{ "B": [ { "Rename": true, "ToChange": 1 }, { "Rename": false, "ToChange": 1 }, { "Rename": "WrongValue", "ToChange": 1 }, { "HasRename": false, "ToChange": 1 }, { "Rename": true, "ToChange": 1 } ] }{ "@jdt.rename": { "@jdt.path": "$.B[?(@.Rename == true)].ToChange", "@jdt.value":"Changed" } }{ "B": [ { "Rename": true, "Changed": 1 }, { "Rename": false, "ToChange": 2 }, { "Rename": "WrongValue", "ToChange": 3 }, { "HasRename": false, "ToChange": 4 }, { "Rename": true, "Changed": 5 } ] }

3. Remove:

If we want to remove any field for the JSON file we can remove them using “@jdt.remove“, we can use condition here as well.

source filetemplate filefinal result
{ "B": [ { "Remove": true }, { "Remove": false }, { "Remove": "WrongValue" }, { "HasRemove": false }, { "Remove": true } ] }{ "@jdt.remove": { "@jdt.path": "$.B[?(@.Remove == true)]" } }{ "B": [ { "Remove": false }, { "Remove": "WrongValue" }, { "HasRemove": false } ] }

Things we couldn’t conclude:

  1. This library doesn’t any API to support the flattening of data. Eg: If we want to flatten the data of first name, and last name to full name, we don’t have any support in the language.
source filetemplate filefinal result
{ "firstName":"John", "lastName":"Max" }Not Supported{ "fullName": "John Max" }