Data validation (source code)

= Data validation

\b[Data validation] checks a value against stated requirements, such as an allowed <data type>, range or relationship between fields. <Parsing> establishes how input fits a syntax; an application's validation rules determine whether the resulting value is suitable for its purpose. In <Python>, `json.loads` performs <JSON> <deserialization>, but it does not know a particular application's requirements.<Python 3.14 documentation>[json module: json.loads and JSONDecoder conversion table]{ref}

For an original example, suppose a program accepts an exact <Python> <integer> object from 0 through 10. Its validation <predicate> is `type(x) is int and 0 <= x <= 10`. After <JSON> decoding, inputs `0`, `3` and `10` pass; `-1`, `11`, `"3"`, `true` and `3.0` fail. All are valid <JSON> texts. The last input becomes a floating-point object, so this particular rule rejects it even though its numerical value is integral. A different application could deliberately accept it.

The rule must therefore be explicit about its intended distinction. Converting every input to an <integer> before checking would change what is accepted and could lose information. Validating after such conversion answers a different question from checking the original decoded <data type>.

Finally, conformity to these rules is not evidence that a value is true. An invented count of 3 passes the range/type check, just as an observed count of 3 would. Validation establishes compliance with the specified <predicate>; establishing the underlying observation requires separate evidence.