Skip to content

feat: serialize array body to JSON in Request and Response#584

Merged
stefan-guggisberg merged 1 commit intomainfrom
feat/array-json-serialization
Apr 8, 2026
Merged

feat: serialize array body to JSON in Request and Response#584
stefan-guggisberg merged 1 commit intomainfrom
feat/array-json-serialization

Conversation

@tripodsan
Copy link
Copy Markdown
Contributor

Summary

  • Extends the non-spec plain-object JSON auto-serialization in Response and Request to also handle arrays
  • new Response([1, 2, 3]) now sets Content-Type: application/json and serializes to [1,2,3]
  • new Request(url, { method: 'POST', body: [1, 2, 3] }) behaves the same way

Fixes #583

Test plan

  • Added should serialize array body to JSON test in test/fetch/response.test.js
  • Added should serialize plain object body to JSON and should serialize array body to JSON tests in test/fetch/request.test.js
  • All 393 tests pass with 100% coverage

🤖 Generated with Claude Code

Extend the non-spec plain-object JSON auto-serialization to also cover
arrays, so that `new Response([1,2,3])` and `new Request(url, { body: [1,2,3] })`
automatically set Content-Type: application/json and serialize the body.

Fixes #583

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@stefan-guggisberg stefan-guggisberg merged commit d813aa5 into main Apr 8, 2026
6 checks passed
@stefan-guggisberg stefan-guggisberg deleted the feat/array-json-serialization branch April 8, 2026 09:28
github-actions bot pushed a commit that referenced this pull request Apr 8, 2026
# [4.3.0](v4.2.3...v4.3.0) (2026-04-08)

### Features

* serialize array body to JSON in Request and Response ([#584](#584)) ([d813aa5](d813aa5)), closes [#583](#583)
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

🎉 This PR is included in version 4.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

Response (and Request) with array body should auto-serialize to JSON

2 participants