Record Field Coalesce Tool
Coalesce first present nonnull field into a supplied target; zero, false and empty strings are valid values, all missing yields null.
Description
Coalesce first present nonnull field into a supplied target; zero, false and empty strings are valid values, all missing yields null.
Coalescing chooses the first usable field from an ordered candidate list. Distinguishing null from other false-like values preserves valid zero, false and empty-text data.
When to use this tool
Coalesce first present nonnull field into a supplied target; zero, false and empty strings are valid values, all missing yields null.
- Prepare the supplied recordsJson, candidateFields, targetField fields for this operation.
- Compare the complete example with the representation used by your own input before carrying the result into another step.
How to use the tool and how it works
- Enter recordsJson, candidateFields, targetField. Use the exact text syntax, units and index conventions explained below.
- Run the tool. If input validation fails, correct the supplied fields before interpreting any result.
- Read result.records. Interpret false, null and empty lists using the distinctions below; they can be valid outputs.
For each record, find the first candidate field that exists as an own property and is not null. Replace targetField with that value, or null when no candidate qualifies, retaining other members.1
| Input field | Meaning and representation | Accepted input |
|---|---|---|
| recordsJson | JSON text, entered as one text field. The decoded structure is illustrated below; it is not a separate file. | Text |
| candidateFields | candidate fields. | At most 128 strings, each at most 128 UTF-16 code units |
| targetField | target field. | Text; at most 8,192 UTF-16 code units, subject to the grammar above |
For the JSON text fields, the following decoded structures show the example records before they are serialized into input strings. Keep field names, list nesting and value types as shown.
[
{
"field": "recordsJson",
"decoded": [
{
"a": null,
"b": 0
},
{}
]
}
] | Output field | Interpretation |
|---|---|
| result | Object containing the named outputs below. |
| result.records | The records list in the ordering and representation described above. |
{
"input": {
"recordsJson": "[{\"a\":null,\"b\":0},{}]",
"candidateFields": [
"a",
"b"
],
"targetField": "x"
},
"output": {
"result": {
"records": [
{
"a": null,
"b": 0,
"x": 0
},
{
"x": null
}
]
}
}
} Limitations and assumptions
- The target is overwritten even if it already exists. Candidate order matters; zero, false and empty text are selected rather than skipped, and nested paths are not interpreted.
- Decoded JSON is bounded to 20,000 nodes and 32 nesting levels; record arrays have at most 128 records. Parsed number values use JavaScript floating point rather than arbitrary-precision decimal arithmetic.
- Every declared top-level field is required and unexpected fields are rejected. Numeric inputs must be finite; ordinary text fields are bounded to 8,192 UTF-16 code units, with tighter operation-specific limits where stated.
- Ordinary string lists have at most 128 entries of at most 128 code units each; numeric lists and matrices have separate bounded size checks. Nonfinite results and excessively large serialized outputs are rejected.
- Indexes are zero-based and spans have an exclusive end unless explicitly stated otherwise. A valid false, null or empty-list result is distinct from malformed input.
Alternative or Complementary methods
For document-wide requirements, combine these structural inventories with an explicit JSON Schema. Preserve the distinction between missing properties and null values, and between numbers and numeric-looking strings when building joins or indexes.
References
Similar or alternative tools
- Record Field Presence Matrix
Build a record/field own-presence matrix; an explicit null member counts as present.
- Record Field Projection Tool
Project explicit own fields from each JSON record without fabricating missing members.