---
schema_version: "1"
id: f536af2a3aea76857f52de52c2fb447ec7780774838d95d7b99a01b0c14687f9
title: keySet
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.9/dw-objects-functions-keyset.md
canonical_url: https://docs.mulesoft.com/dataweave/2.9/dw-objects-functions-keyset
source_site: docs.mulesoft.com
content_type: documentation
content_hash: a38ded0c067ac32bf840d942bee2904de803c2c35fab3900f7edd41860363ee1
description: MuleSoft Documentation Site
release: "2.9"
latest: false
---
---
product: DataWeave
version: 2.9
---

# keySet

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## keySet<K, V>(obj: { (K)?: V }): Array<K>

Returns an array of key names from an object.

_This function is **Deprecated**. Use [dw::Core::keysOf](https://docs.mulesoft.com/dataweave/2.9/dw-core-functions-keysof), instead._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>object</code></p></td><td><p>The object to evaluate.</p></td></tr></tbody></table>

### Example

This example returns the keys from the input object.

#### Source

```DataWeave
%dw 2.0
import * from dw::core::Objects
output application/json
---
{ "keySet" : keySet({ "a" : true, "b" : 1}) }
```

#### Output

```JSON
{ "keySet" : ["a","b"] }
```

### Example

This example illustrates a difference between `keySet` and `nameSet`. Notice that `keySet` retains
the attributes (`name` and `lastName`) and namespaces (`xmlns`) from the XML input, while `nameSet`
returns `null` for them because it does not retain them.

#### Source

```DataWeave
%dw 2.0
import * from dw::core::Objects
var myVar = read('<users xmlns="http://test.com">
                     <user name="Mariano" lastName="Achaval"/>
                     <user name="Stacey" lastName="Duke"/>
                  </users>', 'application/xml')
output application/json
---
{ keySetExample: flatten([keySet(myVar.users) map $.#,
                          keySet(myVar.users) map $.@])
}
++
{ nameSet: flatten([nameSet(myVar.users) map $.#,
                    nameSet(myVar.users) map $.@])
}
```

#### Output

```JSON
{
  "keySet": [
    "http://test.com",
    "http://test.com",
    {
      "name": "Mariano",
      "lastName": "Achaval"
    },
    {
      "name": "Stacey",
      "lastName": "Duke"
    }
  ],
  "nameSet": [
    null,
    null,
    null,
    null
  ]
}
```
