0

It would be helpful if someone could help me on below dataweave expression

[ { "id": "1001", "email": null,
"role": "admin", "updatedAt": "2019-12-04T22:39:00.322000Z", "Attributes": [ { "id": "1001A", "name": "GEO", "value": null }, { "id": "1001B", "name": "Group", "value": "admin" }, { "id": "1001C", "name": "Title", "value": null }, { "id": "1001D", "name": "Location", "value": "New York" } ], "isActive": false }, { "id": "2001", "email": null,
"role": "student", "updatedAt": "2019-12-05T22:39:00.322000Z", "Attributes": [ { "id": "2001A", "name": "GEO", "value": null }, { "id": "2001B", "name": "Group", "value": "admin" }, { "id": "2001C", "name": "Title", "value": null }, { "id": "2001D", "name": "Location", "value": "New York" } ], "isActive": false }, { "id": "3001", "email": null,
"role": "admin", "updatedAt": "2019-12-04T22:39:00.322000Z", "Attributes": [ { "id": "3001A", "name": "GEO", "value": null }, { "id": "3001B", "name": "Group", "value": "admin" }, { "id": "3001C", "name": "Title", "value": null }, { "id": "3001D", "name": "Location", "value": "New York" } ], "isActive": false } ]

And My Output should be like below

[ { "id": "1001", "email": null,
"role": "admin", "updatedAt": "2019-12-04T22:39:00.322000Z", "GEO" : null, "Group":"admin", "Title":null, "Location":"New York", "isActive": false

},
{
    "id": "2001",
    "email": null,            
    "role": "student",
    "updatedAt": "2019-12-05T22:39:00.322000Z", 
    "GEO" : null,
    "Group":"student",
    "Title":null,
    "Location":"New York",
    "isActive": false
},
{
    "id": "3001",
    "email": null,            
    "role": "admin",
    "updatedAt": "2019-12-04T22:39:00.322000Z",
    "GEO" : null,
    "Group":"admin",
    "Title":null,
    "Location":"New York",
    "isActive": false
}

]

1 Answer 1

1

You can use the following DataWeave expression:

%dw 2.0
output application/json
fun toObject(attributes) = ((attributes map ($.name): $.value) reduce ($ ++ $$))
---
payload map (($ - "Attributes") ++ toObject($.Attributes))

Using the provided payload as input, the output payload is:

[
  {
    "id": "1001",
    "email": null,
    "role": "admin",
    "updatedAt": "2019-12-04T22:39:00.322000Z",
    "isActive": false,
    "Location": "New York",
    "Title": null,
    "Group": "admin",
    "GEO": null
  },
  {
    "id": "2001",
    "email": null,
    "role": "student",
    "updatedAt": "2019-12-05T22:39:00.322000Z",
    "isActive": false,
    "Location": "New York",
    "Title": null,
    "Group": "admin",
    "GEO": null
  },
  {
    "id": "3001",
    "email": null,
    "role": "admin",
    "updatedAt": "2019-12-04T22:39:00.322000Z",
    "isActive": false,
    "Location": "New York",
    "Title": null,
    "Group": "admin",
    "GEO": null
  }
]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.