Forum Discussion

jhagist's avatar
jhagist
New Contributor III
7 years ago

Remove File Name From Path

I couldn’t find this anywhere in the community so now that I have it I thought I would share.

I have a path like this file:///eloqua/test/test.json

I want it like this file:///eloqua/test (no file name in the path)

I got the answer from stackexchange

It looks like this in a mapper

Hope this makes someone else’s journey a bit less painful.

  • @amardeep2021

    Hi,

    You can achieve this by using a mapper snap with the following expression:
    $.filter(value => value != null) mapped to the target path $
    this will filter all values out that equal null, keeping only the key-value pairs in which the value is not null.

    Keep in mind this will only work for 1 level of nesting as I noticed your data was. If it does need to work with nested JSON fields it would be a different expression that I can provide you with as well if needed.

  • amardeep2021's avatar
    amardeep2021
    New Contributor III

    Thanks Cole. Kindly share the other expression also.

    Regards,
    Amar.

    • cjhoward18's avatar
      cjhoward18
      Employee

      You can use this expression:

      { filterEmptyKeys: (value, key) => value != null, cleanupTree: value => value instanceof Object ? value.mapValues(this.cleanupTree).filter(this.filterEmptyKeys) : value }.cleanupTree($)

      mapped to the target path $ to remove all null values from a nested JSON object

  • amardeep2021's avatar
    amardeep2021
    New Contributor III

    Thanks Cole again. For the first expression, I am getting none null columns all coming as array for each rows. Is that expected?

    • cjhoward18's avatar
      cjhoward18
      Employee

      Not sure what you mean. Can you share a version of the input-output example?