1
Scalable solution for key-value mapping in LS Data Mapper?
Question asked by Senne Van den Bergh - 9/15/2020 at 11:06 AM
Answered
Hi there!

I am trying to map an external XSD to an internal JSON schema.
Somewhere in that external XSD, there is a placeholder where key-value attributes are passed:

the values in additionalTradeItemClassificationPropertyCode are the keys which correspond with an attribute defined in our internal JSON, for example:
The value in propertyCode corresponds with the value of our JSON attribute.
So for the example above, we know that sdsLegallyRequiredIndicator equals to "NOT_APPLICABLE".

I started using the proposed solution to use an equal function, comparing the key with the additionalTradeItemClassificationPropertyCode and then to filter that result and map it to the correct attribute in my internal JSON:

That works perfectly fine, for a limited set of those mappings.

I have +/- 4500 of those key-value attributes I need to map, so it would seem I need to create 4500 constants, 4500 equal functions, 4500 filters,... not to mention the connectors.

That is a lot of work, therefore I was wondering whether there would be a more scalable solution where I could maybe reuse certain components? Maybe not work with 4500 constants, but having a list in some way?

Many thanks in advance for the help,
Kind regards,
Daan

3 Replies

Reply to Thread
1
Liquid Support Replied
Employee Post Marked As Answer
You can do this using the 'lookup' component, this will map your input id's to your output ones.

The values for the lookup can be entered manually
or imported (which would be easier if you have 4500+)

So the data 
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:noNamespaceSchemaLocation="Source.xsd">
    <CustomData>
        <ID>a</ID>
        <Value>va</Value>
    </CustomData>
    <CustomData>
        <ID>b</ID>
        <Value>vb</Value>
    </CustomData>
    <CustomData>
        <ID>c</ID>
        <Value>vc</Value>
    </CustomData>
    <CustomData>
        <ID>d</ID>
        <Value>vd</Value>
    </CustomData>
    <CustomData>
        <ID>e</ID>
        <Value>ve</Value>
    </CustomData>
</Root>
becomes 
{
	"Values": {
		"Thing a": "va",
		"Thing b": "vb",
		"c": "vc",
		"d": "vd",
		"e": "ve"
	}
}
Note: no mapping data existed for c,d,e so the default behaviour was applied (which was to copy the source id)

See attached sample


0
Senne Van den Bergh Replied
Hi,

thank you very much for the response!
It seems indeed the way to go!

I do have one additional question, the attributes to map to in the JSON target should be defined on the root element, so ideally we wouldn't have that "Values" object in our output.

Thus, I tried the following, I mapped the input to the additionalProperties of the "root" element:


The mapping does not immediately show an error in the error list, however when I try to execute the mapping, I do receive an unrecoverable runtime error:

Any idea of what I am doing wrong here?

Many thanks in advance,
Kind regards,
Daan
1
Liquid Support Replied
Employee Post
After allowing 'additionalItems' in the root JSON schema you can hook it up like this
Which will produce the output 
{
	"Thing a": "va",
	"Thing b": "vb",
	"c": "vc",
	"d": "vd",
	"e": "ve"
}
Note, CustomData is connected to AdditionalProperties, so each CustomData entry will create an additional property, its name will come from the lookup, and we want it to be a string so we hook up the string value.

If you have other types of additional properties you wish to add you can right click on additional properties and 'duplicate' it.

If your still having problems, please post the source/target schemas and some sample data and I'll look into it (create a support ticket it the data is sensitive).

Reply to Thread