Forum Discussion

DaisyTam's avatar
DaisyTam
New Contributor
8 years ago

Mapper Snap : Help with JsonPath

Hi

I appreciate some help in transform the attached input to the attached output.

I have tried using the mapper snap with the following expression
$person.jive.profile[?(value.jive_label == ‘Country’)].value
$person.jive.profile[?(jive_label == ‘Country’)].value

And is getting syntax error.

input.txt (636 Bytes)
output.txt (191 Bytes)

5 Replies

  • The correct way is like this

    Country:

    jsonPath($, "$person.jive.profile[?(@.jive_label=='Country')].value")[0]
    

    Company:

    jsonPath($, "$person.jive.profile[?(@.jive_label=='Company Name')].value")[0]
    

    But, since it will get an array of values, you would want to grap the index 0.

    Let me know if this helps!!

  • DaisyTam's avatar
    DaisyTam
    New Contributor

    This works.

    jsonPath($, “$person.jive.profile[?(value.jive_label==‘Country’)].value”)[0]

    • DaisyTam's avatar
      DaisyTam
      New Contributor

      So ‘Country’ sometimes does not exist. How do I deal with that use case?

      • DaisyTam's avatar
        DaisyTam
        New Contributor

        I solved the problem with

        jsonPath($, “$person.jive.profile[?(value.jive_label==‘Country’)].value”).length > 0 ? jsonPath($, “$person.jive.profile[?(value.jive_label==‘Country’)].value”)[0] : null