Friday, December 18, 2020

Understanding DataWeave's Pluck Function

Main Points

  • the pluck function iterates over each key/value pair of the input object.
  • it retrieves the keys, values, and indexes from the input object.
  • input to the pluck function is an object, and output is an array.

What Is the Pluck Function Used For?

The pluck function is used to retrieve the key, value, and index from an object and output the result to an array. The code snippets in figures 1, 2, and 3 show the retrieval of the object’s key, value, and index using the full reference and the built-in default.

{pet: "cat", name: "Ponsonby"} pluck (value, key, index) -> key
or
{pet: "cat", name: "Ponsonby"} pluck $$
OUTPUT: ["pet", "name"]




from DZone.com Feed https://ift.tt/37ygKIJ

No comments:

Post a Comment