Okta Workflows Tips #85: Delete a Key-Value Pair Using the Object-Unset Function

Short and handy Okta Workflows tips and tricks. Read the full series.

The Object-Unset function allows you to delete a key-value pair from an object. Also, check Okta Workflows Tips #65: Update a JSON Object Using the Object-Set card, which does the opposite.

Creating a JSON object using the Object-Construct function:

Creating a JSON object with the Object-Construct function.
Creating a JSON object with the Object-Construct function.

The JSON object looks like this:

{
"Locations": [
"San Francisco",
"Chicago",
"Seattle"
],
"Name": "Jane Green",
"Email": {
"home": "jane@home.com",
"work": "jane@work.com"
},
"Contractor": "Yes"
}

Using the Object-Unset function to remove the Contractor key:

Removing the Contractor field with the Object-Unset function.
Removing the Contractor field with the Object-Unset function.

Results in the following object:

{
"Locations": [
"San Francisco",
"Chicago",
"Seattle"
],
"Name": "Jane Green",
"Email": {
"home": "jane@home.com",
"work": "jane@work.com"
}
}

You can remove a key from a nested object using a dot:

Removing a nested object key with the Object-Unset function.
Removing a nested object key with the Object-Unset function.

The result is:

{
"Locations": [
"San Francisco",
"Chicago",
"Seattle"
],
"Name": "Jane Green",
"Email": {
"work": "jane@work.com"
}
}

You can also remove an item from a list when you indicate an index:

Removing a list item with the Object-Unset function.
Removing a list item with the Object-Unset function.

The result is:

{
"Locations": [
"San Francisco",
"Chicago"
],
"Name": "Jane Green",
"Email": {
"work": "jane@work.com"
}
}

Okta Workflows resources

Leave a Reply

Discover more from Max Katz

Subscribe now to keep reading and get access to the full archive.

Continue reading