cancel
Showing results for 
Search instead for 
Did you mean: 

SnapLogic Metadata Read - Parsing Question

kindminis
New Contributor

Hi All, 

I am looking to simply parse out the snaps used in a pipeline using the metadata read snap. However, I am having trouble getting the output of the snap_map.property_map.info.label.value to display correctly out of the mapper. I tried to set the mapping root as $snap_map[*], but that does not seem to work. Ideally, I would like to get a final table with pipeline_id, pipeline_name, snap_map_id, snap_map_name. May someone help me with this? Thanks.

kindminis_3-1708927469153.png

kindminis_4-1708927499731.png

 

1 ACCEPTED SOLUTION

ivicakoteski
New Contributor III

Hi @kindminis ,

You can try the following expression in the mapper snap after the SnapLogicRead snap. 

 

$snap_map.keys().map(x=> {"PipelineId":$_id,"PipelineName":$property_map.info.label.value,"SnapId":$snap_map.get(x).instance_id,"SnapName":$snap_map.get(x).property_map.info.label.value})

 

ivicakoteski_0-1708934444044.png
This expression will iterate over all snaps included in the $snap_map and produce an array with your expected elements. You will also need the JSON Splitter snap to get the table form.

ivicakoteski_1-1708934455526.png

BR.
Ivica.

View solution in original post

3 REPLIES 3

ivicakoteski
New Contributor III

Hi @kindminis ,

You can try the following expression in the mapper snap after the SnapLogicRead snap. 

 

$snap_map.keys().map(x=> {"PipelineId":$_id,"PipelineName":$property_map.info.label.value,"SnapId":$snap_map.get(x).instance_id,"SnapName":$snap_map.get(x).property_map.info.label.value})

 

ivicakoteski_0-1708934444044.png
This expression will iterate over all snaps included in the $snap_map and produce an array with your expected elements. You will also need the JSON Splitter snap to get the table form.

ivicakoteski_1-1708934455526.png

BR.
Ivica.

Hi Ivica, 

Thank you for this, as a follow up question. If I want to capture a field that does not always exist in property_map, how would I write the expression? In this case I want to capture property_map.settings.sqlStatement.value if it is present. Thanks. 

Hi @kindminis ,
You just need to extend the object with another element ie. the key and the corresponding value for that key. There are two ways to achieve this:

  1. By using the hasPath function and the ternary operator. You will check if sqlStatement exists in porperty_map.settings in each snap, if so you will get sqlStatement.value, otherwise an empty string will be produced:

 

$snap_map.keys().map(x=> {"PipelineId":$instance_id,"PipelineName":$property_map.info.label.value,"SnapId":$snap_map.get(x).instance_id,"SnapName":$snap_map.get(x).property_map.info.label.value,"SqlStatement":$snap_map.get(x).property_map.settings.hasPath("sqlStatement") ? $snap_map.get(x).property_map.settings.sqlStatement.value : "" })
​

      2. Check the null-safe access option in the mapper and map the required source path to the value.            If property_map.settings.sqlStatement.value does not exist, missing data will be ignored and a                null value will be produced:
ivicakoteski_0-1709155709110.png

 

 

$snap_map.keys().map(x=> {"PipelineId":$instance_id,"PipelineName":$property_map.info.label.value,"SnapId":$snap_map.get(x).instance_id,"SnapName":$snap_map.get(x).property_map.info.label.value,"SqlStatement":$snap_map.get(x).property_map.settings.sqlStatement.value})

 

To summarize, in approach  #1, if property_map.settings.sqlStatement.value will not be present, an empty string will be produced, in approach #2, null will be produced.

Hope this helps!

BR.
Ivica