Skip to content

Conversation

sarahmarshy
Copy link

This PR adds support for configuring JSON encoding options at the client level. This allows setting default JSON encoding behavior for all requests made by a client instance.

Feature

  • Added json_encode_options to client configuration
  • Options are applied when encoding JSON request bodies
  • Supports all standard PHP JSON encoding options (e.g., JSON_UNESCAPED_UNICODE, JSON_INVALID_UTF8_SUBSTITUTE)

Added Tests

  • Test client-level JSON encoding configuration
  • Test nested Unicode characters and invalid UTF-8 handling
  • Test JSON encoding options inheritance
  • Test supplementary plane characters (4-byte Unicode)
  • Test middleware chain cleanup

Example Usage

// Configure client to preserve Unicode characters
$client = new Client([
    'json_encode_options' => JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE
]);

// All JSON requests will use these encoding options
$response = $client->post('/', [
    'json' => ['greeting' => '👋 Hello']
]); // Will preserve Unicode characters in outpu

@sarahmarshy sarahmarshy force-pushed the json-encode-options branch from bbc84ad to 9fa3696 Compare April 4, 2025 06:54
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.

1 participant