Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plumb: Specialized function to convert array to object in Dataweave #53

Open
VictorManhani opened this issue Feb 15, 2023 · 0 comments
Open

Comments

@VictorManhani
Copy link

Frequently we have a necessity to convert an array to object.

I know the syntax using map, braces and parentheses already exists, but this syntax is very loaded and difficult to understand.

Current Syntax Example:

{(array map {($$): $})}

I created a function to facilitate our transformation on this and called it plumb because it makes the process different from pluck which is converting object to array. Here's the example of the function I created:

%dw 2.0
output application/json

fun plumb(array: Array<Any>, func: Any): Object = (
  {(array map {($$): func($)})}
)

var pay = ["Victor", 1, true, {"color": "red"}, ["açaí"]]
---
pay plumb (obj) -> obj

Expected output:

{
    "0": "Victor",
    "1": 1,
    "2": true,
    "3": {"color": "red"},
    "4": ["açaí"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant