-1

I have an array that I want to append only at the end of of each line; The array looks like this;

[
    "9011fc3g-8c8d-43f5-abc7-147845cbdd63",
    "fg8aeb41-210z-49d7-aa25-19da525b6b89",
    "8eb39er-d8g7-462c-9b69-1d5a1e3bf994",
    "67af209a-7535-4f51-95fd-284e2faea223",
    "5b93cf0d-e197-4cea-914b-3742c3aa0847",
    "fe80df52-5427-111f-8fe4-3d510e1857ba",
    "9c3e3323-e52e-44f2-9g34-45ebf93e05e7",
    "33e102e5-bs96-4e5c-ba72-55a5511d1d6f",
    "9197a16d-a263-42ae-a7a3-4ab58dbc4558"
]

an I want it to be like this;

9011fc3g-8c8d-43f5-abc7-155845cbdd63 or id eq
fg8aeb41-210z-49d7-aa25-25da525b6b89 or id eq
8eb39er2-d8g7-462c-9b69-d5a1e3bf994d or id eq
67af209a-7535-4f51-95fd-284e2faea223 or id eq
5b93cf0d-e197-4cea-914b-3742c3aa0847 or id eq
fe80df52-5427-111f-8fe4-3d510e1857ba or id eq
9c3e3323-e52e-44f2-9g34-45ebf93e05e7 or id eq
33e102e5-bs96-4e5c-ba72-55a5511d1d6f or id eq
9197a16d-a263-42ae-a7a3-4ab58dbd1d6f

So append each line with "or id eq" condition and remove all the double quotes, single quote and brackets. I tried with grouping and non catch grouping like this but its not working ([|"|]|,)

Thanks for helping.

aled
  • 21,330
  • 3
  • 27
  • 34
Makavelines
  • 111
  • 6
  • Why does `8eb39er` become `8eb39er2` on the 3rd line? Is that a typo maybe? Also, you seem to want to join all elements in the array into a single string? I'm really not sure if regex is the right tool here and not, for example [joinBy](https://docs.mulesoft.com/dataweave/2.4/dw-core-functions-joinby) – JvdV Feb 03 '22 at 10:50
  • That was another line, but I can select al the element that I want to delete only appending seems hard to get (?:\[|"|\]|,) – Makavelines Feb 03 '22 at 10:53
  • By doing this; %dw 2.0 output application/json --- flatten(payload.value.id) joinBy (' id or eq ') I still keep " at the beginning and the end – Makavelines Feb 03 '22 at 11:55

1 Answers1

0
%dw 2.0
output application/json
var payload = [
    "9011fc3g-8c8d-43f5-abc7-147845cbdd63",
    "fg8aeb41-210z-49d7-aa25-19da525b6b89",
    "8eb39er-d8g7-462c-9b69-1d5a1e3bf994",
    "67af209a-7535-4f51-95fd-284e2faea223",
    "5b93cf0d-e197-4cea-914b-3742c3aa0847",
    "fe80df52-5427-111f-8fe4-3d510e1857ba",
    "9c3e3323-e52e-44f2-9g34-45ebf93e05e7",
    "33e102e5-bs96-4e5c-ba72-55a5511d1d6f",
    "9197a16d-a263-42ae-a7a3-4ab58dbc4558"
]
---
payload reduce ($$ ++ " or id eq " ++ $)
MrM
  • 21
  • 3
  • Thanks @Mrm, after doing reduce or flatten I keep double quotes at the begin and end. In mule 4 it can be done by simply changing the output to text/plain only mule 3 not. Any idea how to handle it? – Makavelines Feb 03 '22 at 13:57