cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Select column based on column availability

ppankaj88
New Contributor

Hi,

I am reading multiple json files from source. where column names and column type are varying from file to file.

For example: In one file, column name is coming as an array and in another file it is coming without array. But for my use case I donโ€™t need to worry about the column type.I only want data to be stored.

Now my question is:
I have below two different columns coming from two different file:
Col 1: jsonPath($, โ€œ$OT.Refs.TripRef[*][โ€˜@BookingRefโ€™]โ€)
Col 2: OT.Refs.TripRef[โ€˜@BookingRefโ€™]

I am reading one by one each file and I want to do following thigs:

  1. If Col 1 is not coming from file 1 then select Col 2
    2- If Col 2 is not coming from file 1 then select Col 1
    3- And both should come under one column name

For Example:

is not available in the file then select then Column name =
1 ACCEPTED SOLUTION

SpiroTaleski
Valued Contributor

Hi @ppankaj88,

You can try with the โ€œhasPathโ€ object function and Conditional(Ternary) operator.

ex: $.hasPath(โ€œcol1โ€) ? $col1 : ($.hasPath(โ€œcol2โ€) ? $col2 : โ€œโ€)

The above expression will check:

  • if col1 is present on the source, then take the col1
  • if col1 is missing from the source, then check if col2 is present on the source
  • if col2 is present on the source then take the col2
  • if both columns are missing then the target will be empty string

Also, I am attaching a simple pipeline as an example:

SL_Community_2020_08_24.slp (4.8 KB)

Hope this helps.

Regards,
Spiro Taleski

View solution in original post

2 REPLIES 2

SpiroTaleski
Valued Contributor

Hi @ppankaj88,

You can try with the โ€œhasPathโ€ object function and Conditional(Ternary) operator.

ex: $.hasPath(โ€œcol1โ€) ? $col1 : ($.hasPath(โ€œcol2โ€) ? $col2 : โ€œโ€)

The above expression will check:

  • if col1 is present on the source, then take the col1
  • if col1 is missing from the source, then check if col2 is present on the source
  • if col2 is present on the source then take the col2
  • if both columns are missing then the target will be empty string

Also, I am attaching a simple pipeline as an example:

SL_Community_2020_08_24.slp (4.8 KB)

Hope this helps.

Regards,
Spiro Taleski

ppankaj88
New Contributor

Thank you for providing solutionโ€ฆitโ€™s worked for me