A developer encountered an error when trying to save a JSON-type metafield with an empty/nil value in Shopify’s API. The API returns a validation error stating “value can’t be blank” when attempting to set metafield.value to nil or an empty array [] for JSON-type metafields.
Key Finding:
Another user investigated how Shopify’s native admin handles this scenario and discovered that metafields are deleted entirely when their values are removed, rather than being updated to empty/nil values.
Solution:
Instead of updating the metafield value to nil or empty, use the delete method (via REST API’s MetafieldDelete or running delete in code) to remove the metafield completely. This approach successfully clears the values and avoids the validation error.
Resolution:
The original poster confirmed this solution works correctly when deleting the metafield rather than attempting to save it with an empty value.
Summarized with AI on November 11.
AI used: claude-sonnet-4-5-20250929.
From API call I can not sent nil value for metafield.value if child_products_data is empty, because it gives error like #<ShopifyAPI::Errors::HttpResponseError: {"errors":{"value":["can’t be blank."]}.
You are correct. Metafields are simply deleted when their value is removed. However, this only works for metafields that do not have a JSON type. For JSON type metafields, updating a nil value is prevented.