Payments are experiencing issues due to temporary restrictions in Russia. If your payment does not go through, please submit a support request.Our support team is available 24/7 — we are always here to help with hosting and server issues.We are now accepting requests for dedicated server rental and colocation services in our data center.Reminder: we recommend enabling backups for additional data protection.A new VPS/VDS lineup with NVMe storage and improved performance is now available.Maintenance work on some servers has been completed. All services are operating normally.
Article5 min readViews0

Empty Field in the API: When to Save a Value and When to Clear It

A missing property, null, an empty string, and zero can all signify different changes. We examine the partial update contract using an online store exchange example.

Comments 0

Three round openings: one with a purple sphere, one empty, and one closed; different field states in the exchange
In this article

Consider an order exchange: the order contained the comment "Call one hour before delivery." After syncing with the accounting system, the field became empty, even though the buyer deleted nothing. The log shows no error: the sender transmitted an empty value, and the receiver faithfully saved it. The failure occurred earlier, when two distinct intents were converted into the same data packet.

For a partial update, you must separately agree on three actions: keep the original value, set a new value, and clear the field. Standard JSON does not provide such an agreement. A missing property, null, an empty string, and zero are distinct in data; the meaning of the change is defined by the contract of the specific method. This is especially useful to verify when exchanging data between a 1C-Bitrix store and 1C, a CRM, or a custom delivery service.

One field, three different requests

Take a hypothetical order with the field comment. The customer changes only the delivery address. If they do not transmit comment at all, this may mean "do not touch the comment." If the buyer deletes the text, the integration must transmit a separate, unambiguous intent to clear the comment. Converting both cases into an empty string during export is not allowed: it becomes impossible to restore the original intent from such a message.

The boundary of applicability is crucial here. In one API, the absence of a field means the old value is preserved, while in another, the method accepts the complete object state and requires mandatory fields. The word "update" in a method name guarantees nothing. First, we determine whether we are sending changes or a new full version of the data; then we choose the representation of emptiness.

There is a standard approach for partial updates: JSON Merge Patch, described in RFC 7396. In such a patch object, a missing property remains unchanged, a scalar value or array replaces the previous one, and null signifies property deletion. Nested objects are processed recursively using the same rules. This rule applies specifically to this format, not as a universal interpretation of any JSON request.

Suppose the original object contains {"comment":"Позвонить за час до доставки","quantity":2}. The patch {"quantity":0} sets the quantity to zero and preserves the comment. The patch {"comment":null} deletes the comment property. The patch {"comment":""} leaves the property with an empty string. The last two results may appear identical in an order form, but for the next handler, they are distinct.

If the domain model needs to store null as a distinct value, this deletion semantics is inconvenient. It is impossible to agree that the same action means both 'save an unknown value' and 'delete the property.' You must choose a different representation for the operation or a different change format and describe it explicitly.

JSON Merge Patch: a missing field preserves the comment, an empty string clears the text, and null removes the property
A tutorial example for a single field; the rules apply to JSON Merge Patch.

Do not lose zero along the way

The condition 'if the value is not empty, send the field' looks compact. However, such a check erroneously excludes valid data from being sent. A quantity of zero, free shipping, and a disabled flag can all be meaningful values.

For example, under a conditional contract, the quantity is allowed to change to zero. You must check for the presence of the property and the validity of its value, not the general 'truthiness' of the value in the programming language. If the sender excludes zero from the payload, the receiver of a partial update will retain the original two units. In this case, correct JSON delivery results in an incorrect product quantity.

Intermediate transformations are checked separately: export from 1C, the exchange module model, the queue, and the external API client. One component may distinguish a missing property from null, while the next replaces both cases with a default value. Therefore, it is useful to compare the anonymized source package with the package immediately before sending, without limiting the check to fields in the store interface.

An empty array is another agreement

A list of phone numbers or attachments raises a new question: are individual element changes transmitted, or the entire list? In JSON Merge Patch, an array is replaced entirely. An empty array [] replaces the old array with an empty one; transmitting a single element does not mean 'add only this element to the rest.'

In a custom integration method, the rules may differ. However, the field name will not explain whether an empty list means clearing, lack of available information, or an export generation error. The most unpleasant case occurs when the sender cannot retrieve attachments and substitutes an empty array: a technical failure turns into a command to delete relationships.

If the information cannot be obtained, it is better to return the observed error for this operation or defer the field update according to an agreed rule. Do not treat an unknown state as confirmed emptiness. Nor should a field be silently skipped if the contract requires the full object version: in that case, the package must be rejected before application.

What to check on an integration copy

For a single selected field, the initial state and expected result are fixed in advance. Then, individual cases are checked:

  • the field is missing from the request;

  • null is passed;

  • an empty string is passed;

  • zero or false is passed, if the field type allows it;

  • an empty array is passed, if the field contains a list;

  • an incorrect type is passed, for example, a string instead of the expected number.

The check must verify not only the method's response but also the persisted state. Did the property remain in the object? Was the previous value preserved? Were list relationships removed? Did the next stage replace the value with a default zero? Such a set is executed on a test copy with conditional data. The objects presented here are educational examples; they do not confirm the behavior of a specific 1C-Bitrix module.

For each field, a concise rule is derived: what absence signifies, how clearing is expressed, which values are permissible, and who is authorized to modify them. This rule is agreed upon between the sender and receiver before transformation configuration. Only then does an empty comment represent a deliberate user action rather than an unintended side effect of another system attempting to fill the gap.

Discussion 0

Share your experience and ask questions. Comments without links appear after editorial review.

No comments yet. Start the discussion.