CheckMySchema

Structured data explained

Is null an empty string?

Short answer: no. Null means no value; an empty string is a string of length 0. Clear definitions with JSON, JavaScript, PowerShell and C++ examples, plus practical validation tips.

    Minimalist full frame diagram with three slate panels labeled null empty string and blank whitespace each with short .NET and Java code snippets

    No. Null is not an empty string. In JSON, null is a distinct literal value, while an empty string is a string whose length is zero. The application defines whether null means unknown, not set, or something else.

    What each term means

    • Null: a distinct literal denoting no value. In JSON, null is its own value type alongside string, number, boolean, object and array. See RFC 8259 (RFC 8259).
    • Empty string: a string that contains zero characters. In JSON, strings are defined as a sequence of zero or more Unicode characters, so "" is valid and distinct from null (RFC 8259).
    Close up of two minimalist code panels on a midnight blue CheckMySchema background comparing C# String.IsNullOrEmpty(value) and Java value == null || value.isEmpty illustrating check

    Why the distinction matters

    Conflating null and empty string changes program logic, validation and storage. A missing value (null) often signals “unknown” or “not set,” while an empty string may mean “intentionally provided but empty.” Treating them the same without an explicit rule can cause faulty validation, confusing user messages or unexpected exceptions.

    How common platforms handle it

    JSON data

    • JSON defines both null and string as separate value types. A string may be empty (""), and that is not the same as null (RFC 8259).
    {
      "name": "",
      "nickname": null
    }

    JavaScript

    • typeof "" is "string"; typeof null is "object". They require different checks in code, and trimming whitespace can be necessary when deciding if input is "empty" (MDN: JavaScript null).
    const a = "";          // empty string
    const b = null;        // null
    if (b === null || (typeof a === "string" && a.trim().length === 0)) {
      // treat as empty input
    }
    

    Distinguishing null, empty, blank and missing in data

    When you validate or consume JSON-like data, decide how to handle these cases per field:

    • null: value explicitly absent (for example, unknown).
    • empty string: provided, but zero characters ("").
    • blank string: only whitespace (" "). Some apps normalize this to empty.
    • missing property: no key present at all.
    {
      "email": null,
      "displayName": "",
      "tag": "   "
    }

    In JSON Schema, presence and value type are separate decisions. A property can be required yet allow null; another can be optional yet accept only strings when present. Use required to control presence and a type rule to control allowed values. A string minLength of 1 rejects an empty string, but it does not reject a space-only string by itself. Define a separate whitespace policy if needed (JSON Schema object reference).

    Minimalist 2D vector decision flowchart with a central diamond and two rounded panels representing String IsNullOrEmpty and null plus isBlank handling without text or numbers

    Practical patterns for safe checks

    • Check for null first to avoid dereferencing errors.
    • Normalize text inputs (trim whitespace) before applying emptiness rules where appropriate.
    • Document per-field policy so clients and services agree on behavior.

    Minimal examples

    The following function demonstrates one application policy: treat null, empty strings and space-only strings as empty input. This does not make those values equal. It deliberately does not classify undefined as empty; handle a missing property separately according to your data contract.

    JavaScript example (MDN JavaScript reference):

    function isEmptyInput(v) {
      if (v === null) return true;
      if (typeof v === 'string' && v.trim().length === 0) return true;
      return false;
    }
    

    Decide and enforce your null vs empty policy

    Related reading on CheckMySchema

    CheckMySchema logo

    FAQ

    Is an empty array or object the same as null?

    No. In JSON, arrays and objects can be empty ([]) or ({}), and those are valid values, distinct from null (RFC 8259).

    Can JSON carry both null and empty string?

    Yes. JSON supports null as a literal and strings of zero or more characters; "" is an empty string and is not equal to null (RFC 8259).

    Related guides

    Official sources and further reading