JSON Validation with TWTValidation by Jill Cohen

JSON Validation with TWTValidation by Jill Cohen

Lightning Talk from March 2015 CocoaHeads Raleigh/Durham

Transcript

  1. 2.

    JSON VALIDATION PROBLEM: Writing validation code is tedious and error-prone

    Requires frequent & consistent type checking Often fails silently Repetitive Low readability Perform mapping before completing validation
  2. 3.

    JSON VALIDATION USING TWTVALIDATION GET JSON VALUE VALIDATE VALUE AGAINST

    EXPECTATIONS IF PASSES,
 PERFORM MAPPING Describe expected format as a single entity, not with successive if statements
  3. 4.

    ▸ Usage: JSON VALIDATION VALIDATE, THEN MAP INTO MODEL OBJECTS

    CONFIDENTLY Correct types!
 Won’t crash! Required values are guaranteed to be present!
  4. 7.

    JSON VALIDATION EXAMPLE SCHEMA: WEATHER is described
 by… Explicit when

    allowing null Enforce types Require existence of properties Define common structure once
  5. 9.

    JSON VALIDATION UNDER THE HOOD PARSES SCHEMA INTO ABSTRACT SYNTAX

    TREE VALIDATE VALUE PROCESSES TREE USING VISITOR PATTERN TO GENERATE VALIDATOR Composes existing classes of TWTValidators 
 + some classes purpose-built for this Requires input to be a valid schema Nested validators perform their specific validation tasks