Mapping Backend Schema to Frontend Data Model
Conscia's Schema Mapping Components allow you to restructure and/or merge the data from your backend sources into a data model that your applications can more easily consume. It involves identifying the data elements in the source systems and specifying how they should be transformed and mapped to the corresponding data elements in the target system(s).
Here is an example of what the Schema Mapping Components can be used for:
Conscia provides the following Schema Mapping Components which allow you to specify the target structure and how the target structure's elements are populated by the various sources:
Component Type | Description |
---|---|
Object Mapper | The Object Mapper works with the current response object and allows you to remap the fields within the response. The configuration allows you to define a target structure in its entirety (using JSON or the drag and drop interface) and specify source expressions as values for each JSON property. The source expressions are either query or script notations that operate on source data that is provided as part of the component configuration. |
Property Mapper | The Property Mapper allows you to specify target properties using a string notation and source expressions that will populate the target properties using one of a few notations. |
Schema Mapper Components may be chained together (like any other Component) for complicated transformations.
Object Mapper Component
Component Configuration
The Object Mapper Component can be configured via the Developer UI within DX Studio or via APIs like any other component.
Here is what the UI looks like:
The Object Mapper enables you to individually define the mapping logic for each object within your target schema, using various expressions such as JSONPath, JMESPath, JavaScript, or JSONata. It provides you with the freedom and flexibility to map each object to different upstream data sources according to your unique business requirements.
Whether you're overwriting existing properties with new data, or adding entirely new properties, the Object Mapper streamlines the process, ensuring your final target schema is a customized representation of your target data model.
Here is how the Object Mapper is evaluated by the DX Engine:
Initialization: The process commences with the construction of the initial JSON schema object. This beginning framework ultimately shapes up into the target schema.
Sequential Evaluation: Each subsequent schema object in the sequence is evaluated, with the sequence order bearing significance as each new schema may adjust preceding entries.
Configuring Mapping Logic: Here's where the power of customization comes into play. For each object in the target schema, you can individually define its mapping logic. Whether it's JSONPath, JMESPath, JavaScript, or JSONata, the choice is yours. This allows you to map each object to different upstream data sources based on your requirements.
Overwriting Existing Properties: If the newly evaluated schema object contains properties that already exist in the evolving target schema, those existing properties are replaced with new values. This ensures that the most recent information takes priority.
Adding New Properties: When the evaluated schema object introduces properties not yet included in the target schema, these new properties are seamlessly added.
Progressive Refinement: The process of evaluating, customizing mapping logic, overwriting, and adding is iteratively applied to each schema object. This gradually refines the target schema, giving it shape and depth according to your specifications.
Completion: After all schema objects in the sequence have been evaluated, merged, and customized, the result is the definitive target schema. This is a tailored integration of all individual schema objects, shaped according to your data model needs.
This process underscores the flexibility and control you have over your data structure using the target schema. By determining the mapping logic for each object, you ensure that your final schema fits your specific needs, regardless of the complexity or diversity of your upstream data sources.
Here are the configuration parameters required for this Component:
Parameter Name | Parameter Property | Description |
---|---|---|
Default Source | defaultSource | Data value to be used in the mapper expressions if not overridden within the mapper definition. |
Default Expression Type | defaultExpressionType | One of: jmespath , jsonpath , jsonata , javascript |
Object Maps | objectMaps | Array objects that descrbe how to map sources to an JSON object. objectMaps: [{ source, expressionType, object }] |
Object Maps / Source Data | source | The data value to be used for the expressions in this set of property mappings. |
Object Maps / Expression Type | expressionType | One of: jmespath , jsonpath , jsonata , javascript |
Object Maps / Object | mappings | JSON Object to be mapped. Each property value is an expression |
Source Expressions
JMESPath
JMESPath is an extremely flexible query language for JSON and its usage is described in detail on their website.
JSONPath
The JSONPath is another query language for JSON and is described here and here.
JSONata
JSONata allows for anything from simple JSON querying to more complicated scripting logic and is described here.
Conscia Javascript Expressions
A Javascript Expression allows for one JS expression that has access to the following variables and functions:
Variable/Function | Description |
---|---|
_ | Lodash utility |
encodeURI | Native Javascript function |
encodeURIComponent | Native Javascript function |
JSON | Native Javascript Object |
Array | Native Javascript Object |
Promise | Native Javascript Object |
Object | Native Javascript Object |
DateTime | Date and Time manipulation utility from the luxon library |
contextField(contextField) | This function returns the value of the specified Context Field. By using this function anywhere in a Component's configuration, the Component will not execute until after any other Components (that populate the specified Context Field) have run. |
componentResponse(componentCode) | This function returns the response from the specified Component. By using this function anywhere in a Component's configuration, the Component will not execute until after the specified Component has completed. |
componentStatus(componentCode) | This function returns the status of the specified Component. By using this function anywhere in a Component's configuration, the Component will not execute until after the specified Component has completed. |
Property Mapper Component
Property Mapper is another type of Schema Mapper offered by the DX Engine. This powerful tool allows you to hone in on specific properties within your target schema, enabling precise control over your data structure. With the Property Mapper, you can define 'target properties' through a straightforward string notation that pinpoints the exact path to any specific property within your target schema. What's more, you can populate these target properties using 'source expressions' from various expressions types. It's this granularity and flexibility that allows you to tailor your data model to your precise needs.
Component Configuration
Parameter Name | Parameter Property | Description |
---|---|---|
Default Source | defaultSource | Data value to be used in the mapper expressions if not overridden within the mapper definition. |
Default Expression Type | defaultExpressionType | One of: jmespath , jsonpath , jsonata , javascript |
Property Maps | propertyMaps | Array objects that descrbe how to map source to target properties. propertyMaps: [{ source, expressionType, mappings }] |
Property Maps / Source Data | source | The data value to be used for the expressions in this set of property mappings. |
Property Maps / Expression Type | expressionType | One of: jmespath , jsonpath , jsonata , javascript |
Property Maps / Mappings | mappings | Array of objects that map a target property to an expression to be evaluated. mappings: [{ targetProperty, sourceExpression }] |
Property Maps / Mappings / Target Property | targetProperty | The path in the final object that should contain the evaluated source expression. |
Property Maps / Mappings / Source Expression | sourceExpression | Expression to be evaluated and mapped to the specified target property. |
The sequence of the mapping is non-deterministic. Therefore, it is important that the specied targetProperties are not overlapping in any way.
To see an example of how to use the Object Mapper, see the tutorial, How to Unify Product and CMS Records.