Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Missing Value Operators

Operators for checking whether data fields are absent.

missing

Check for missing fields in the data.

Syntax:

{ "missing": [key1, key2, ...] }
{ "missing": key }

Arguments:

  • key1, key2, … - Field names to check

Returns: Array of missing field names.

Examples:

// Check single field
{ "missing": "name" }
// Data: { "age": 25 }
// Result: ["name"]

// Check multiple fields
{ "missing": ["name", "email", "phone"] }
// Data: { "name": "Alice", "phone": "555-1234" }
// Result: ["email"]

// All fields present
{ "missing": ["name", "age"] }
// Data: { "name": "Alice", "age": 25 }
// Result: []

// All fields missing
{ "missing": ["name", "age"] }
// Data: {}
// Result: ["name", "age"]

// Nested fields
{ "missing": ["user.name", "user.email"] }
// Data: { "user": { "name": "Alice" } }
// Result: ["user.email"]

// A key that exists with a null value counts as present
{ "missing": ["x"] }
// Data: { "x": null }
// Result: []

Notes:

  • Only absent paths are reported. A key that exists with a null or empty-string value counts as present, so { "missing": ["x"] } with { "x": null } or { "x": "" } returns []. This differs from json-logic-js, which also reports keys whose value is null or ""
  • Dot-separated names walk nested objects ("user.email")

Common Patterns

Require all fields:

{ "!": { "missing": ["name", "email", "password"] } }
// Returns true only if all fields are present

Check if any field is missing:

{ "!!": { "missing": ["name", "email"] } }
// Returns true if ANY field is missing

Conditional validation:

{ "if": [
    { "missing": ["required_field"] },
    { "throw": "Missing required field" },
    "ok"
]}

Try it:


missing_some

Require that at least N of a set of fields are present; the missing ones are returned only when fewer than N are present.

Syntax:

{ "missing_some": [minimum, [key1, key2, ...]] }

Arguments:

  • minimum - Minimum number of fields that should be present
  • [key1, key2, ...] - Array of field names to check

Returns: Array of missing field names if fewer than minimum are present, empty array otherwise.

Examples:

// Need at least 1 of these contact methods
{ "missing_some": [1, ["email", "phone", "address"]] }
// Data: { "email": "a@b.com" }
// Result: [] (1 present, requirement met)

// Data: {}
// Result: ["email", "phone", "address"] (0 present, need at least 1)

// Need at least 2 of these
{ "missing_some": [2, ["name", "email", "phone"]] }
// Data: { "name": "Alice" }
// Result: ["email", "phone"] (only 1 present, need 2)

// Data: { "name": "Alice", "email": "a@b.com" }
// Result: [] (2 present, requirement met)

// Data: { "name": "Alice", "email": "a@b.com", "phone": "555" }
// Result: [] (3 present, exceeds requirement)

Notes:

  • Presence follows the same rule as missing: a key holding null or "" counts as present
  • minimum must be an integer; a non-integer minimum (for example 2.5 or "1") falls back to 1
  • With fewer than two arguments ({ "missing_some": [1] }) the result is []

Common Patterns

Require at least one contact method:

{ "!": { "missing_some": [1, ["email", "phone", "fax"]] } }
// Returns true if at least one contact method is provided

Flexible field requirements:

{ "if": [
    { "missing_some": [2, ["street", "city", "zip", "country"]] },
    "Please provide at least 2 address fields",
    "Address accepted"
]}

Require majority of fields:

{ "!": { "missing_some": [3, ["field1", "field2", "field3", "field4", "field5"]] } }
// Returns true if at least 3 of 5 fields are present

Try it:


Comparison: missing vs missing_some

Scenariomissingmissing_some
All fields required{ "!": { "missing": [...] } }N/A
At least N requiredComplex logic needed{ "!": { "missing_some": [N, [...]] } }
Check which are missingReturns missing listReturns missing list if < N present
No minimumAppropriateUse with minimum=1

Integration with Validation

Form validation example:

{ "if": [
    { "missing": ["username", "password"] },
    { "throw": "VALIDATION_ERROR" },
    { "if": [
        { "missing_some": [1, ["email", "phone"]] },
        { "throw": "CONTACT_REQUIRED" },
        "valid"
    ]}
]}

Conditional field requirements:

// If business account, require company name
{ "if": [
    { "==": [{ "var": "accountType" }, "business"] },
    { "!": { "missing": ["companyName", "taxId"] } },
    true
]}