Skip to content

Conversation

@isaac-vicentini
Copy link
Contributor

This contribution adds a reusable Flow Action that removes duplicate objects from a JSON array based on a specified key. It is designed to simplify data cleanup and normalization in Flows and Subflows.

How It Works

The Flow Action accepts a JSON array of objects and removes duplicates according to a field specified by the user.
You can choose whether to keep the first or last occurrence, and optionally make the comparison case-insensitive and trim whitespace before evaluating duplicates.

Inputs

array: JSON string representing an array of objects to process.
Example:

[
  {"email":" [email protected] ","name":"A"},
  {"email":"[email protected]","name":"A-dup"},
  {"email":"[email protected]","name":"B"}
]

key: Object field name used to detect duplicates. Example: email.
keep: Determines whether to keep the first or last occurrence of duplicated entries.
case_insensitive: When true, treats field values as case-insensitive ([email protected] equals [email protected]).
trim: When true, trims whitespace before comparing values (e.g., " [email protected] " equals "[email protected]").

Outputs

JSON object containing the cleaned list and metadata:

{
  "success": true,
  "count_in": 3,
  "count_out": 2,
  "removed": 1,
  "items": [
    {"email":"[email protected]","name":"A"},
    {"email":"[email protected]","name":"B"}
  ]
}

Example Use Case

Use this Action to remove duplicate user records by email before performing bulk insert or update operations via Flow Designer.
This helps ensure data integrity, especially when processing large datasets or integrating external APIs.

…JSON array based on a specified key.

The Action supports options to keep either the first or last occurrence, handle case sensitivity, and trim whitespace from values.
It outputs a structured JSON object containing the cleaned list and useful metadata (total input, output, and removed items).
@github-actions
Copy link

Valid PR for ActionPack

Thank you for your contribution. This PR complies with the CONTRIBUTING.md.
A maintainer will review this shortly. In the meantime, Happy Hacking!

@SapphicFire SapphicFire self-assigned this Oct 28, 2025
Copy link
Contributor

@SapphicFire SapphicFire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thank you for your contribution

@SapphicFire SapphicFire merged commit f596e82 into ServiceNowDevProgram:main Oct 28, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants