Skip to content

fix: isJson assertion should accept arrays as valid JSON#7620

Open
abhishek-bruno wants to merge 1 commit intousebruno:mainfrom
abhishek-bruno:fix/isJson-assertion-accept-arrays
Open

fix: isJson assertion should accept arrays as valid JSON#7620
abhishek-bruno wants to merge 1 commit intousebruno:mainfrom
abhishek-bruno:fix/isJson-assertion-accept-arrays

Conversation

@abhishek-bruno
Copy link
Copy Markdown
Member

@abhishek-bruno abhishek-bruno commented Mar 30, 2026

Description

JIRA

  • Fixes the isJson assertion to accept JSON arrays (e.g. ["A55001213ZX0A"]), which were incorrectly rejected
  • Updates existing test and adds new test cases for array variants

Context

The isJson chai property explicitly excluded arrays with !Array.isArray(obj). This caused res.body: isJson assertions to fail for API responses returning JSON arrays — a valid and common response format.

Fixes #7556

Test plan

  • Existing isJson tests updated and passing
  • New tests for: array of strings, empty array, array of objects
  • Plain object assertions still pass
  • Cross-realm object assertions still pass
  • String and null still correctly fail

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Summary by CodeRabbit

  • Bug Fixes

    • The isJson assertion now treats arrays (including empty arrays and arrays of objects) as valid JSON; previously it only accepted plain objects.
  • Tests

    • Test suite updated to mark arrays of primitives, empty arrays, and arrays of objects as passing JSON cases while keeping non-array negatives (e.g., strings, null) failing.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dffbf813-eaae-4412-a159-eb7a84916448

📥 Commits

Reviewing files that changed from the base of the PR and between 2eba837 and 5301b71.

📒 Files selected for processing (2)
  • packages/bruno-js/src/runtime/assert-runtime.js
  • packages/bruno-js/tests/runtime.spec.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bruno-js/src/runtime/assert-runtime.js

Walkthrough

The chai isJson assertion was relaxed to treat arrays as JSON in addition to plain objects. Tests were updated to expect arrays (including arrays of strings, empty arrays, and arrays of objects) to pass isJson; other behaviors (strings, null) remain failing.

Changes

Cohort / File(s) Summary
Assertion Logic
packages/bruno-js/src/runtime/assert-runtime.js
Widened isJson predicate to accept arrays by adding Array.isArray(obj) alongside the plain-object check.
Tests
packages/bruno-js/tests/runtime.spec.js
Updated expectations: makeResponse([1,2,3]) now passes; added positive cases for arrays of strings, empty arrays, and arrays of objects; negative cases for string and null remain.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

size/S

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • naman-bruno
  • bijin-bruno

Poem

Arrays once barred from JSON's door,
Now welcomed in with room for more.
Tests updated, assertions sing,
Small fix, small joy — a tidy thing. 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: allowing the isJson assertion to accept arrays as valid JSON.
Linked Issues check ✅ Passed The PR fully addresses issue #7556 by fixing the isJson assertion to accept JSON arrays, including comprehensive test coverage for array variants.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the isJson assertion for arrays; no unrelated modifications detected in the implementation or tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@abhishek-bruno abhishek-bruno force-pushed the fix/isJson-assertion-accept-arrays branch 2 times, most recently from 483554a to 2eba837 Compare March 31, 2026 14:18
…ce test coverage

- Modified the JSON validation logic to accept arrays as valid JSON objects.
- Updated tests to ensure correct behavior for various array scenarios, including empty arrays and arrays of strings and objects.
@abhishek-bruno abhishek-bruno force-pushed the fix/isJson-assertion-accept-arrays branch from 2eba837 to 5301b71 Compare April 1, 2026 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assert Section Signals Invalid JSON For Array With String Values

1 participant