Skip to content

fix: handle null values in fixture JSON parsing#1545

Open
tadhgdowdall wants to merge 5 commits intostripe:masterfrom
tadhgdowdall:fix/fixtures-null-values
Open

fix: handle null values in fixture JSON parsing#1545
tadhgdowdall wants to merge 5 commits intostripe:masterfrom
tadhgdowdall:fix/fixtures-null-values

Conversation

@tadhgdowdall
Copy link
Copy Markdown

Reviewers

r? @
cc @stripe/developer-products

Summary

I created this fix based on a previous unmerged PR and a bug which still has not been fixed
Github Issue: 1447

Fixes an issue where null values in Stripe CLI fixtures were silently dropped instead of being sent to the API.

Previously, fields set to null were omitted from the request, causing existing values to persist or defaults to be applied. This made it impossible to explicitly clear fields using fixtures.

This change updates ParseMapForFormData and ParseArrayForFormData to serialize null values as empty form fields (""), aligning with Stripe’s API behavior where empty values indicate unsetting a field.

Adds tests to verify null value handling in both simple maps and nested arrays.


Testing API Requests

1. Created temporary test fixture file (test-null-fields.json)

{
  "_meta": {
    "template_version": 0
  },
  "fixtures": [
    {
      "name": "test_customer",
      "path": "/v1/customers",
      "method": "post",
      "params": {
        "name": "Test Null Fix",
        "email": "[email protected]",
        "address": {
          "line1": "123 Test Street",
          "line2": null,
          "city": "Paris",
          "postal_code": "75001",
          "country": "FR",
          "state": null
        }
      }
    }
  ]
}

2. Run the fixture

stripe --api-key sk_test_XXX fixtures test-null-fields.json

Output:

Setting up fixture for: test_customer
Running fixture for: test_customer

3. Retrieve the customer

stripe --api-key sk_test_XXX customers list --limit 1

Before Fix Results

line2 and state are both null, the null values were dropped

{
  "object": "list",
  "data": [
    {
      "id": "cus_UKj99LStyc9Tn8",
      "object": "customer",
      "address": {
        "city": "Paris",
        "country": "FR",
        "line1": "123 Test Street",
        "line2": null,
        "postal_code": "75001",
        "state": null
      },
      "balance": 0,
      "created": 1776160574,
      "currency": null,
      "customer_account": null,
      "default_source": null,
      "delinquent": false,
      "description": null,
      "discount": null,
      "email": "[email protected]",
      "invoice_prefix": "E322QXB8",
      "invoice_settings": {
        "custom_fields": null,
        "default_payment_method": null,
        "footer": null,
        "rendering_options": null
      },
      "livemode": false,
      "metadata": {},
      "name": "Test Null Fix",
      "phone": null,
      "preferred_locales": [],
      "shipping": null,
      "tax_exempt": "none",
      "test_clock": null
    }
  ],
  "has_more": true,
  "url": "/v1/customers"
}

After Fix Results

line2 and state are now empty strings "" , the null values were properly sent as empty form fields

{
  "object": "list",
  "data": [
    {
      "id": "cus_UKjSKslUWXLYWg",
      "object": "customer",
      "address": {
        "city": "Paris",
        "country": "FR",
        "line1": "123 Test Street",
        "line2": "",
        "postal_code": "75001",
        "state": ""
      },
      "balance": 0,
      "created": 1776161709,
      "currency": null,
      "customer_account": null,
      "default_source": null,
      "delinquent": false,
      "description": null,
      "discount": null,
      "email": "[email protected]",
      "invoice_prefix": "BXN3FV3O",
      "invoice_settings": {
        "custom_fields": null,
        "default_payment_method": null,
        "footer": null,
        "rendering_options": null
      },
      "livemode": false,
      "metadata": {},
      "name": "Test Null Fix",
      "phone": null,
      "preferred_locales": [],
      "shipping": null,
      "tax_exempt": "none",
      "test_clock": null
    }
  ],
  "has_more": true,
  "url": "/v1/customers"
}

@tadhgdowdall tadhgdowdall requested a review from a team as a code owner April 14, 2026 16:18
@tomer-stripe
Copy link
Copy Markdown
Collaborator

@tadhgdowdall hey this caused the linter to fail. If you can fix that we can merge after!

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