Skip to content

feat/CUS-11393-Update JSON actions to handle nested key matches#358

Merged
akhil-testsigma merged 2 commits into
devfrom
feat/CUS-11393-Update-JSON-actions-to-handle-nested-key-matches
Mar 18, 2026
Merged

feat/CUS-11393-Update JSON actions to handle nested key matches#358
akhil-testsigma merged 2 commits into
devfrom
feat/CUS-11393-Update-JSON-actions-to-handle-nested-key-matches

Conversation

@akhil-testsigma
Copy link
Copy Markdown
Contributor

@akhil-testsigma akhil-testsigma commented Mar 18, 2026

Publish this addon as PUBLIC

Addon Name: Update JSON File
Jarvis Link: https://jarvis.testsigma.com/ui/tenants/2817/addons
Jira : https://testsigma.atlassian.net/browse/CUS-11393
Update JSON actions to handle nested key matches

Summary by CodeRabbit

  • New Features
    • Enhanced JSON update functionality with improved recursive handling for nested structures (objects and arrays).

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 18, 2026

📝 Walkthrough

Walkthrough

The PR updates the Maven artifact version from 1.0.2 to 1.0.3 and refactors JSON traversal logic in two UpdateSingleValueBasedOnKey implementations by adding Lombok's @EqualsAndHashCode annotation and converting the updateNestedKey method to support recursive traversal through nested objects and arrays with boolean return feedback.

Changes

Cohort / File(s) Summary
Version Update
update_json_file/pom.xml
Incremented project version from 1.0.2 to 1.0.3.
Web JSON Traversal Enhancement
update_json_file/src/main/java/com/testsigma/addons/web/UpdateSingleValueBasedOnKey.java
Added @EqualsAndHashCode(callSuper = false) annotation with Lombok import. Refactored updateNestedKey from void to boolean return type and broadened signature from ObjectNode to JsonNode. Enhanced JSON traversal to recursively detect and update values within container nodes (objects/arrays) with early termination on match.
Windows JSON Traversal Enhancement
update_json_file/src/main/java/com/testsigma/addons/windows/UpdateSingleValueBasedOnKey.java
Refactored updateNestedKey from void to boolean return type with broadened JsonNode signature. Narrowed attribute matching to value nodes only and added recursive traversal through nested containers (objects/arrays), returning boolean to propagate update success up the call stack.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • Ganesh-Testsigma
  • vigneshtestsigma

Poem

🐰 A rabbit hops through JSON trees,
With @EqualsAndHashCode, if you please!
Recursive hops through arrays bright,
Boolean returns, everything right! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: updating JSON actions to handle nested key matches. This is the primary focus across both modified Java files and directly aligns with the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/CUS-11393-Update-JSON-actions-to-handle-nested-key-matches
📝 Coding Plan
  • Generate coding plan for human review comments

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
update_json_file/src/main/java/com/testsigma/addons/windows/UpdateSingleValueBasedOnKey.java (1)

23-28: Missing @EqualsAndHashCode annotation for consistency with web version.

The web variant of this class has @EqualsAndHashCode(callSuper = false) added, but this windows version does not. For consistency and to suppress Lombok warnings about extending a class without explicit equals/hashCode handling, consider adding the same annotation here.

Proposed fix

Add the import:

import lombok.EqualsAndHashCode;

Then add the annotation:

 `@Data`
+@EqualsAndHashCode(callSuper = false)
 `@Action`(actionText = "JSON: Update the JSON file at File-Path by finding Key-Name with Key-Value, updating Key-To-Update to New-Value, and storing the file path in variable-name",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@update_json_file/src/main/java/com/testsigma/addons/windows/UpdateSingleValueBasedOnKey.java`
around lines 23 - 28, The class UpdateSingleValueBasedOnKey is missing the
Lombok `@EqualsAndHashCode` annotation that the web variant uses; add import
lombok.EqualsAndHashCode and annotate the class with
`@EqualsAndHashCode`(callSuper = false) above the class declaration (alongside
`@Data` and `@Action`) to match the web version and suppress equals/hashCode
warnings when extending WebAction.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@update_json_file/src/main/java/com/testsigma/addons/web/UpdateSingleValueBasedOnKey.java`:
- Around line 141-146: The current findAndUpdate logic calls
updateNestedKey(jsonObject, keyToUpdate, newValue) then immediately returns
true, ignoring updateNestedKey's boolean result; change findAndUpdate so it
captures the boolean result from updateNestedKey and only returns true when that
result is true (otherwise continue searching and ultimately return false if no
update occurred). Update any related logging in findAndUpdate/execute to reflect
success only when updateNestedKey returned true so execute() doesn't report
false successes.

In
`@update_json_file/src/main/java/com/testsigma/addons/windows/UpdateSingleValueBasedOnKey.java`:
- Around line 141-145: The method findAndUpdate currently calls
updateNestedKey(jsonObject, keyToUpdate, newValue) but ignores its boolean
return; change findAndUpdate to capture the result (e.g., boolean updated =
updateNestedKey(...)) and only return true when updated is true, otherwise
continue searching (or return false if fully finished without updates). Ensure
execute() uses the boolean returned by findAndUpdate to decide success/failure
so that a missing key leads to a false/failed result instead of a false success;
reference updateNestedKey, findAndUpdate, and execute to locate and propagate
the boolean properly.

---

Nitpick comments:
In
`@update_json_file/src/main/java/com/testsigma/addons/windows/UpdateSingleValueBasedOnKey.java`:
- Around line 23-28: The class UpdateSingleValueBasedOnKey is missing the Lombok
`@EqualsAndHashCode` annotation that the web variant uses; add import
lombok.EqualsAndHashCode and annotate the class with
`@EqualsAndHashCode`(callSuper = false) above the class declaration (alongside
`@Data` and `@Action`) to match the web version and suppress equals/hashCode
warnings when extending WebAction.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b75e53fb-6d20-42d0-b8dc-aa6e01692eed

📥 Commits

Reviewing files that changed from the base of the PR and between 995ee96 and 88ab9be.

📒 Files selected for processing (3)
  • update_json_file/pom.xml
  • update_json_file/src/main/java/com/testsigma/addons/web/UpdateSingleValueBasedOnKey.java
  • update_json_file/src/main/java/com/testsigma/addons/windows/UpdateSingleValueBasedOnKey.java

Comment on lines 141 to 146
if (key.equals(attributeName)) {
if (value != null && value.asText().equals(attributeValue)) {
if (value != null && value.isValueNode() && value.asText().equals(attributeValue)) {
logger.info(" Found attribute: " + attributeName + " with value " + attributeValue);
updateNestedKey(jsonObject, keyToUpdate, newValue);
return true; // Stop after finding and updating
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Return value of updateNestedKey is ignored, causing false success reports.

Same issue as the windows variant: when the matching object is found but keyToUpdate doesn't exist within it, updateNestedKey returns false, but findAndUpdate returns true regardless. This leads to execute() reporting success when no update occurred.

Proposed fix
                 if (key.equals(attributeName)) {
                     if (value != null && value.isValueNode() && value.asText().equals(attributeValue)) {
                         logger.info("  Found attribute: " + attributeName + " with value " + attributeValue);
-                        updateNestedKey(jsonObject, keyToUpdate, newValue);
-                        return true; // Stop after finding and updating
+                        if (updateNestedKey(jsonObject, keyToUpdate, newValue)) {
+                            return true; // Stop after finding and updating
+                        }
+                        // Continue searching if key wasn't found in this object
                     }
                 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (key.equals(attributeName)) {
if (value != null && value.asText().equals(attributeValue)) {
if (value != null && value.isValueNode() && value.asText().equals(attributeValue)) {
logger.info(" Found attribute: " + attributeName + " with value " + attributeValue);
updateNestedKey(jsonObject, keyToUpdate, newValue);
return true; // Stop after finding and updating
}
if (key.equals(attributeName)) {
if (value != null && value.isValueNode() && value.asText().equals(attributeValue)) {
logger.info(" Found attribute: " + attributeName + " with value " + attributeValue);
if (updateNestedKey(jsonObject, keyToUpdate, newValue)) {
return true; // Stop after finding and updating
}
// Continue searching if key wasn't found in this object
}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@update_json_file/src/main/java/com/testsigma/addons/web/UpdateSingleValueBasedOnKey.java`
around lines 141 - 146, The current findAndUpdate logic calls
updateNestedKey(jsonObject, keyToUpdate, newValue) then immediately returns
true, ignoring updateNestedKey's boolean result; change findAndUpdate so it
captures the boolean result from updateNestedKey and only returns true when that
result is true (otherwise continue searching and ultimately return false if no
update occurred). Update any related logging in findAndUpdate/execute to reflect
success only when updateNestedKey returned true so execute() doesn't report
false successes.

Comment on lines 141 to +145
logger.info(" Found attribute: " + attributeName + " with value " + attributeValue);
updateNestedKey(jsonObject, keyToUpdate, newValue);
return true; // Stop after finding and updating
}
} else {
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Return value of updateNestedKey is ignored, causing false success reports.

When the matching object is found but keyToUpdate doesn't exist within it, updateNestedKey returns false. However, findAndUpdate returns true regardless, causing execute() to report success even when no update occurred.

Proposed fix
                 if (key.equals(attributeName)) {
                     if (value != null && value.isValueNode() && value.asText().equals(attributeValue)) {
                         logger.info("  Found attribute: " + attributeName + " with value " + attributeValue);
-                        updateNestedKey(jsonObject, keyToUpdate, newValue);
-                        return true; // Stop after finding and updating
+                        if (updateNestedKey(jsonObject, keyToUpdate, newValue)) {
+                            return true; // Stop after finding and updating
+                        }
+                        // Continue searching if key wasn't found in this object
                     }
                 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
logger.info(" Found attribute: " + attributeName + " with value " + attributeValue);
updateNestedKey(jsonObject, keyToUpdate, newValue);
return true; // Stop after finding and updating
}
} else {
}
logger.info(" Found attribute: " + attributeName + " with value " + attributeValue);
if (updateNestedKey(jsonObject, keyToUpdate, newValue)) {
return true; // Stop after finding and updating
}
// Continue searching if key wasn't found in this object
}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@update_json_file/src/main/java/com/testsigma/addons/windows/UpdateSingleValueBasedOnKey.java`
around lines 141 - 145, The method findAndUpdate currently calls
updateNestedKey(jsonObject, keyToUpdate, newValue) but ignores its boolean
return; change findAndUpdate to capture the result (e.g., boolean updated =
updateNestedKey(...)) and only return true when updated is true, otherwise
continue searching (or return false if fully finished without updates). Ensure
execute() uses the boolean returned by findAndUpdate to decide success/failure
so that a missing key leads to a false/failed result instead of a false success;
reference updateNestedKey, findAndUpdate, and execute to locate and propagate
the boolean properly.

@akhil-testsigma akhil-testsigma merged commit 4743436 into dev Mar 18, 2026
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