Introduction
I have a requirement to extract the keys and values from a dataset like the following:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | { "account1" : { "accountID" : "1234" , "name" : "Mary Loo" , "balance" : 234.32 }, "account2" : { "accountID" : "1234" , "name" : "Lauren Flor" , "balance" : 234.32 }, "account3" : { "accountID" : "1234" , "name" : "Mary Loo" , "balance" : 234.32 } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | [ { "accountID" : "1234" , "name" : "Mary Loo" , "balance" : 234.32 }, { "accountID" : "1234" , "name" : "Lauren Flor" , "balance" : 234.32 }, { "accountID" : "1234" , "name" : "Mary Loo" , "balance" : 234.32 } ] |
1 2 3 4 5 | [ "account1" , "account2" , "account3" ] |
Understanding Dataweave pluck Function
Dataweave has devised a function particularly for this kind of requirement. Here is the solution to extract values of a HashMap1 2 3 4 | %dw 2.0 output application/json --- payload pluck (item, key, index) -> item |
1 2 3 4 | %dw 2.0 output application/json --- payload pluck $ |
1 2 3 4 | %dw 2.0 output application/json --- payload pluck (item, key, index) -> key |
1 2 3 4 | %dw 2.0 output application/json --- payload pluck $$ |
No comments:
Post a Comment