Files
n8n-docs/docs/data/expression-reference/object.md
Kartik Balasubramanian 96e6ba167d Revamp the data section of n8n docs (#4077)
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
2026-02-25 14:30:33 +00:00

257 lines
5.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Object
## _`Object`_.**`compact()`**
**Description:** Removes all fields that have empty values, i.e. are <code>null</code> or <code>""</code>
**Syntax:** _`Object`_.compact()
**Returns:** Object
**Source:** Custom n8n functionality
**Examples:**
```javascript
// obj = {'x':null, 'y':2, 'z':''}
obj.compact() //=> {'y':2}
```
## _`Object`_.**`hasField()`**
**Description:** Returns <code>true</code> if there is a field called <code>name</code>. Only checks top-level keys. Comparison is case-sensitive.
**Syntax:** _`Object`_.hasField(name)
**Returns:** Boolean
**Source:** Custom n8n functionality
**Parameters:**
* `name` (String) - The name of the key to search for
**Examples:**
```javascript
// obj = {'name':'Nathan', 'age':42}
obj.hasField('name') //=> true
```
```javascript
// obj = {'name':'Nathan', 'age':42}
obj.hasField('Name') //=> false
obj.hasField('inventedField') //=> false
```
## _`Object`_.**`isEmpty()`**
**Description:** Returns <code>true</code> if the Object has no keys (fields) set or is <code>null</code>
**Syntax:** _`Object`_.isEmpty()
**Returns:** Boolean
**Source:** Custom n8n functionality
**Examples:**
```javascript
// obj = {'name': 'Nathan'}
obj.isEmpty() //=> false
```
```javascript
// obj = {}
obj.isEmpty() //=> true
```
## _`Object`_.**`isNotEmpty()`**
**Description:** Returns <code>true</code> if the Object has at least one key (field) set
**Syntax:** _`Object`_.isNotEmpty()
**Returns:** Boolean
**Source:** Custom n8n functionality
**Examples:**
```javascript
// obj = {'name': 'Nathan'}
obj.isNotEmpty() //=> true
```
```javascript
// obj = {}
obj.isNotEmpty() //=> false
```
## _`Object`_.**`keepFieldsContaining()`**
**Description:** Removes any fields whose values dont at least partly match the given <code>value</code>. Comparison is case-sensitive. Fields that arent strings will always be removed.
**Syntax:** _`Object`_.keepFieldsContaining(value)
**Returns:** Object
**Source:** Custom n8n functionality
**Parameters:**
* `value` (String) - The text that a value must contain in order to be kept
**Examples:**
```javascript
// obj = {'name': 'Mr Nathan', 'city':'hanoi', age: 42 }
obj.keepFieldsContaining('Nathan') //=> {'name': 'Mr Nathan'}
```
```javascript
// obj = {'name': 'Mr Nathan', 'city':'hanoi', age: 42 }
obj.keepFieldsContaining('nathan') //=> {}
obj.keepFieldsContaining('han') //=> {'name': 'Mr Nathan', 'city':'hanoi'}
```
## _`Object`_.**`keys()`**
**Description:** Returns an array with all the field names (keys) the object contains. The same as JavaScripts <code>Object.keys(obj)</code>.
**Syntax:** _`Object`_.keys()
**Returns:** Array<String>
**Source:** Custom n8n functionality
**Examples:**
```javascript
// obj = {'name': 'Mr Nathan', age: 42 }
obj.keys() //=> ['name', 'age']
```
## _`Object`_.**`merge()`**
**Description:** Merges the two Objects into a single one. If a key (field name) exists in both Objects, the value from the first (base) Object is used.
**Syntax:** _`Object`_.merge(otherObject)
**Returns:** Object
**Source:** Custom n8n functionality
**Parameters:**
* `otherObject` (Object) - The Object to merge with the base Object.
**Examples:**
```javascript
// obj1 = {'name':'Nathan', 'age': 42}
// obj2 = {'name':'Jan', 'city': 'hanoi'}
obj1.merge(obj2) //=> {'name':'Jan', 'city': 'hanoi', 'age':42}
```
## _`Object`_.**`removeField()`**
**Description:** Removes a field from the Object. The same as JavaScripts <code>delete</code>.
**Syntax:** _`Object`_.removeField(key)
**Returns:** Object
**Source:** Custom n8n functionality
**Parameters:**
* `key` (String) - The name of the field to remove
**Examples:**
```javascript
// obj = {'name':'Nathan', 'city':'hanoi'}
obj.removeField('name') //=> {'city':'hanoi'}
```
## _`Object`_.**`removeFieldsContaining()`**
**Description:** Removes keys (fields) whose values at least partly match the given <code>value</code>. Comparison is case-sensitive. Fields that arent strings are always kept.
**Syntax:** _`Object`_.removeFieldsContaining(value)
**Returns:** Object
**Source:** Custom n8n functionality
**Parameters:**
* `value` (String) - The text that a value must contain in order to be removed
**Examples:**
```javascript
// obj = {'name': 'Mr Nathan', 'city':'hanoi', age: 42}
obj.removeFieldsContaining('Nathan') //=> {'city':'hanoi', age: 42}
```
```javascript
// obj = {'name': 'Mr Nathan', 'city':'hanoi', age: 42}
obj.removeFieldsContaining('han') //=> {age: 42}
obj.removeFieldsContaining('nathan') //=> {'name': 'Mr Nathan', 'city':'hanoi', age: 42}
```
## _`Object`_.**`toJsonString()`**
**Description:** Converts the Object to a JSON string. Similar to JavaScripts <code>JSON.stringify()</code>.
**Syntax:** _`Object`_.toJsonString()
**Returns:** String
**Source:** Custom n8n functionality
**Examples:**
```javascript
// obj = {'name':'Nathan', age:42}
obj.toJsonString() //=> '{"name":"Nathan","age":42}'
```
## _`Object`_.**`urlEncode()`**
**Description:** Generates a URL parameter string from the Objects keys and values. Only top-level keys are supported.
**Syntax:** _`Object`_.urlEncode()
**Returns:** String
**Source:** Custom n8n functionality
**Examples:**
```javascript
// obj = {'name':'Mr Nathan', 'city':'hanoi'}
obj.urlEncode() //=> 'name=Mr+Nathan&city=hanoi'
```
## _`Object`_.**`values()`**
**Description:** Returns an array with all the values of the fields the Object contains. The same as JavaScripts <code>Object.values(obj)</code>.
**Syntax:** _`Object`_.values()
**Returns:** Array<String>
**Source:** Custom n8n functionality
**Examples:**
```javascript
// obj = {'name': 'Mr Nathan', age: 42 }
obj.values() //=> ['Mr Nathan', 42]
```